python - 使用 RK 45 方法求解耦合方程组

标签 python

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/

相关文章:

python - Pandas - 根据列内的排名删除单元格

Python Flask 应用程序在 TOTP 错误中前导零。 ( python 2.7)

python - 找到最长重复的长度?

python - 使用Python改进多边形内的点计算

python - 包含字符串的多个 DataFrame 的逐项加权平均值

python - 远程运行 TensorFlow

python - python 类 __init__ 函数的 PyCharm 模板

python - 如何在 PySpark 中创建 merge_asof 功能?

python - 导入错误 : No module named endpoints_proto_datastore. ndb

python - 类型错误 : <lambda>() missing 1 required positional argument: 'count' when using lambda to sort a python 3 dictionary