簡體   English   中英

function() 缺少 4 個必需的位置參數

[英]function() missing 4 required positional arguments

問題顯示在第 90 行。

我認為主要問題在於數據框。 因此,在從function計算值后,我返回一個數據框。 該函數在 for 循環中用於生成不同的行,如下所示。

代表情節:我一直在嘗試一些線索,但仍然不起作用

在此處輸入圖片說明

import math as m
import matplotlib.pyplot as plt
import pandas as pd

#tst=529
#temp=524
#dtube=0.41

def function(ConstantA,ConstantB,tst,temp,dtube):
# variables and constants
    k0 = 38.9
    e = 90000
    lambd=-328200
    dp=0.003;roecat= 1670; porosity=0.4; cpa=95.2; cpb=32; cpc= 102.81;cpc= 71; ma=28;mb=32;mc=44;md=16; viscosity=0.25e-4;tst=tst;
    dtube=dtube;ntube=25000; ltube= 9.8288; dw=1;wplot=0; yar=0;ybr=0;np=0;pi=3.1416; areacstube= pi * (dtube ** 2) / 4; wmaxtube=ltube * areacstube * roecat;wmax=wmaxtube * ntube;
    # Initial conditions
    w=0; fc=0; fa0=0.8125; fb0=0.26;fd0=2.175;fr=0;temp=temp; p=17; fain=fr * yar+fa0; fbin=fr * ybr+fb0;fdin=fd0;

    # Integration loop
    # Bring arrays outside so it would not get overwritten while inside the loop
    wp = []
    tempp = []
    pp = []
    yap = []
    ycp = []

    # np = 0    Remove, no need to track indices when appending in Python
    while w < wmax:
        fa=fain-fc; fb=fbin-fc; fd=fdin; ya=fa / (fa+fb+fc+fd); yb=fb / (fa+fb+fc+fd); yc=fc / (fa+fb+fc+fd); yd=fd / (fa+fb+fc+fd);
        k=k0*m.exp(-e / 8.314 / temp);rate=k*(ya*p)**0.5*(yb*p)**0.7;
        roegasmolar=p / (temp * 1.01325 * 82.057e-3); flowvoltube= (fa+fb+fc+fd) / roegasmolar / ntube;
        maverage=ya * ma+yb * mb+yc * mc +yd * md; roegas=roegasmolar * maverage;
        vel=flowvoltube / areacstube; reynolds=dp * vel * roegas / viscosity;
        friction= (1-porosity) * (1.75+150 * (1-porosity) / reynolds) / (porosity ** 3);
        u= ConstantA + ConstantB * reynolds / dp
        #u=0.01545+0.6885e-6 * reynolds / dp;
        #u=0.6


   # Save for plotting
        if w >= wplot:
            # Just removed ';' and used newline so it looks cleaner
            wp.append(w/100)
            tempp.append(temp)
            pp.append(p)
            yap.append(ya*100)
            ycp.append(yc*100)
            wplot = wplot + 10

        # Deriyative evaluation
        dfcdw = rate
        dpdw = friction * ltube * roegas * (vel ** 2) / (dp * wmax * 1e5)
        dtempdw = (- lambd * rate-4 * u * (temp-tst) / (roecat * dtube)) / (cpa * fa+cpb * fb+cpc * fc)

        # Integration
        fc = fc + dfcdw * dw
        temp = temp + dtempdw * dw
        p = p + dpdw * dw
        w = w + dw

        if p < 10:
            break
#df = pd.DataFrame(wp,tempp,ycp,yap,pp)
    print(type(pp))
    all = pd.DataFrame({'wp': wp,'tempp': tempp,'ycp': ycp,'yap': yap,'pp': pp,})
    return all

data = {
    'ConstantA': [0.01545, 0.6, 0.6, 0.6, 0.6],
    'ConstantB': [0.6885e-6, 0, 0, 0, 0],
    'tst': [523, 529, 531, 527, 533],
    'temp': [523, 524, 524, 524, 524],
    'dtube': [0.041, 0.041, 0.041, 0.041, 0.041]
}

df2 = pd.DataFrame(data)

fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2)
fig.suptitle('Cooled;Tst=523')
ax1.set_ylabel('T(K)')
ax2.set_ylabel('y(C%)')
ax3.set_ylabel('yA ()')
ax3.set_xlabel('w (1000 ka)')
ax4.set_ylabel('E (bar)')
ax4.set_xlabel('w (1000 kg)')

# `for`-loop

for index, row in df2.iterrows():
    plot3 = function(row)

    ax1.plot(plot3['wp'], plot3['tempp'])
    ax2.plot(plot3['wp'], plot3['ycp'])
    ax3.plot(plot3['wp'], plot3['yap'])
    ax4.plot(plot3['wp'], plot3['pp'])

# after `for`-loop

plt.tight_layout()  # Automatic adjustment of pyplot so ylabels dont overlap
plt.subplots_adjust(top=0.9)  # Adjust plots to put space beween title and subplot
plt.show()





#for index, row in df2.iterrows():
#   plot3.apppend(plot(row['ConstantA'], row['ConstantB'],row['tst'], row['temp'],row['dtube']))

您正在調用function(row) ,它只包含所需的 5 個參數中的一個參數(即ConstantA,ConstantB,tst,temp,dtube )。

如果您想解壓縮行中的每個項目,以便 if 對應於每個參數,您可以改為執行function(*row)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM