I am trying to solve the System of coupled differential equation but I got following error can any one resolve this problem
dY[1] = (1/M*C_p)((m_c*C_p*(Y[0]-Y[1]))-(U_l*(A_s_2)*(Y[1]-Ta)))
TypeError: 'float' object is not callable
import math
import scipy.integrate as spi
import numpy as np
import pandas as pd
def odes(t,Y):
m_c=0.9
C_p =4200
Tc_O=91
U_l =0.8
D_st=2
L_s=1
rho=1000
V=0.5
M=(rho*V)/3
A_s_1=((math.pi*pow(D_st,2))/4)+((math.pi*D_st*L_s)/3)
A_s_2=((math.pi*D_st*L_s))/3
A_s_3=((math.pi*pow(D_st,2))/4)+((math.pi*D_st*L_s)/3)
Ta =20
dY = np.zeros((3))
dY[0] = (1/M*C_p)*((m_c*C_p*(Tc_O-Y[0]))-(U_l*(A_s_1)*(Y[0]-Ta)))
dY[1] = (1/M*C_p)((m_c*C_p*(Y[0]-Y[1]))-(U_l*(A_s_2)*(Y[1]-Ta)))
dY[2] = (1/M*C_p)((m_c*C_p*(Y[1]-Y[2]))-(U_l*(A_s_3)*(Y[2]-Ta)))
return dY
t_start, t_end = 0, 3600.0
Y = np.array([91,89,75]);
Yres = spi.solve_ivp(odes, [t_start, t_end], Y, method='RK45', max_step=60)
#---- Results ---------------------
yy = pd.DataFrame(Yres.y).T
tt = np.linspace(t_start,t_end,yy.shape[0])
print(yy)
最佳答案
问题出在这里:
dY[1] = (1/M*C_p)((m_c*C_p*(Y[0]-Y[1]))-(U_l*(A_s_2)*(Y[1]-Ta)))
^
|
No multiplication sign!
Python 不像数学。如果有两组彼此相邻的括号且它们之间没有运算符,则并不意味着乘法。它的意思是“调用函数”
所以如果你这样做:
print((3)(4))
您将收到此错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'int' object is not callable
您在该行下方也遇到了同样的问题。
关于python - 使用 RK 45 方法求解耦合方程组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70510616/