2

リスト内のすべての数値の方程式の値を返す関数が必要です。24 個のパラメーターのリストがあり、このリストのすべての値について方程式を解く必要があります。

これが私のリストを取得する方法です:

wlist=[]

def w(i):

    for i in range(24):
        Calctruesolar=((i*60/1440)*1440+eq_time()+4*long-60*timezone)%1440
        if Calctruesolar/4<0:
            Calcw=(Calctruesolar/4)+180
            wlist.append(Calcw)
            print(Calcw)
        else:
            Calcw=(Calctruesolar/4)-180
            wlist.append(Calcw)
            print(Calcw)

次に、リストは次のとおりです。

>>> wlist=
[166.24797550450222, -178.75202449549778, -163.75202449549778, -148.75202449549778, -133.75202449549778, -118.75202449549778, -103.75202449549778, -88.75202449549778, -73.75202449549778, -58.75202449549778, -43.75202449549778, -28.75202449549778, -13.752024495497778, 1.2479755045022216, 16.24797550450222, 31.24797550450222, 46.24797550450222, 61.24797550450222, 76.24797550450222, 91.24797550450222, 106.24797550450222, 121.24797550450222, 136.24797550450222, 151.24797550450222]

ここで、次の関数を使用します。

def hourly_radiation(wlist):

    for i in wlist:
        Calcrt=(math.pi/24)*(a()+b()*math.cos(math.radians(i)))*((math.cos(math.radians(i)))-math.cos(math.radians(wss())))/(math.sin(math.radians(wss()))-((math.pi*wss()/180)*math.cos(math.radians(wss()))))
        CalcI=Calcrt*radiation
        print(Calcrt,CalcI)

だから、リスト内のすべての値に対してCalcrtandを受け取りたいです。CalcIしかし、うまくいきません。インターネットやチュートリアルで情報を探していましたが、何も見つかりませんでした。

4

1 に答える 1

0

これを試して:

def hourly_radiation(wlist):
    rt_list = []
    I_list = []
    for i in wlist:
        Calcrt = (math.pi/24)*(a()+b()*math.cos(math.radians(i)))*((math.cos(math.radians(i)))-math.cos(math.radians(wss())))/(math.sin(math.radians(wss()))-((math.pi*wss()/180)*math.cos(math.radians(wss()))))
        CalcI = Calcrt*radiation
        rt_list.append(Calcrt)
        i_list.append(CalcI)
        print(Calcrt,CalcI)
    dict = {}
    dict["Calcrt"] = rt_list
    dict["CalcI"] = i_list
    return dict

これは、2 つのリストを含む辞書として値を返します。要件に一致する任意のデータ構造を使用できます。

次のように、各ループ実行でタプルを作成し、それをリストに追加して返すこともできます。

def hourly_radiation(wlist):
    rt_list = []
    data = ()
    for i in wlist:
        Calcrt = (math.pi/24)*(a()+b()*math.cos(math.radians(i)))*((math.cos(math.radians(i)))-math.cos(math.radians(wss())))/(math.sin(math.radians(wss()))-((math.pi*wss()/180)*math.cos(math.radians(wss()))))
        CalcI = Calcrt*radiation
        data = (Calcrt, CalcI)
        print(Calcrt, CalcI)
        rt_list.append(data)
    return rt_list

このコードを実行またはテストしていませんが、動作することを願っています。

これを出発点として使用し、コピー アンド ペースト ソリューションとして使用しないでください。

于 2013-10-22T09:43:47.017 に答える