我试图用sympy解决由4个微分方程组成的系统。我收到“ NotImplementedError”。有解决方法吗?
我要解决的ode的集合是:
![ODE]:https://imgur.com/Xa5fwlt
我尝试用数字值替换R12到R45符号。我继续收到相同的错误。
import sympy as sp
import numpy as np
import matplotlib.pyplot as plt
# Define symbols
m1, m2, m3, m4 = sp.symbols('m1 m2 m3 m4', real = True, positive=True)
c1, c2, c3, c4 = sp.symbols('c1 c2 c3 c4', real = True, positive=True)
R12, R25, R23, R34, R45 = sp.symbols('R12 R25 R23 R34 R45', real = True, positive=True) #0.2, 0.1, 2.7, 0.5, .6
T1, T2, T3, T4 = sp.symbols('T1 T2 T3 T4', cls=sp.Function)
qp, qel = sp.symbols('qp qel')
T5 = 25 # ambient temperature
# Define equations
eq1 = -sp.Eq(sp.Derivative(T1(t), t)) + - (T1(t)-T2(t)) / (R12 * m1 * c1)
eq2 = -sp.Eq(sp.Derivative(T2(t), t)) + 1 / (m2 * c2) * ((T1(t) - T2(t))/R12 + (T5-T2(t))/R25 - (T2(t)-T3(t))/R23)
eq3 = -sp.Eq(sp.Derivative(T3(t), t)) + 1 / (m3 * c3) * ((T2(t) - T3(t))/R23 + (T4(t)-T3(t))/R34 - qp)
eq4 = -sp.Eq(sp.Derivative(T4(t), t)) + 1 / (m4 * c4) * (qp - (T4(t) - T3(t))/R34 + (T4(t)-T5)/R45)
eq = (eq1, eq2, eq3, eq4)
funct = (T1(t), T2(t), T3(t), T4(t))
# Solve
sp.dsolve(eq, funct)
我希望收到这组微分方程的符号解。 结果是“ NotImplementedError”
答案 0 :(得分:0)
您用于创建方程式的语法不正确。 Eq
需要接受两个参数,左手边和右手边。
eq1 = sp.Eq(sp.Derivative(T1(t), t), + - (T1(t)-T2(t)) / (R12 * m1 * c1))
eq2 = sp.Eq(sp.Derivative(T2(t), t), + 1 / (m2 * c2) * ((T1(t) - T2(t))/R12 + (T5-T2(t))/R25 - (T2(t)-T3(t))/R23))
eq3 = sp.Eq(sp.Derivative(T3(t), t), + 1 / (m3 * c3) * ((T2(t) - T3(t))/R23 + (T4(t)-T3(t))/R34 - qp))
eq4 = sp.Eq(sp.Derivative(T4(t), t), + 1 / (m4 * c4) * (qp - (T4(t) - T3(t))/R34 + (T4(t)-T5)/R45))
我这样做了,而dsolve需要一段时间来计算解决方案。它必须对4x4符号矩阵求幂,这涉及到找到符号特征值,即求解四次方very complicated in the general case。
SymPy在这里可能会得到改善。用数字参数替换符号参数应该可以使其运行更快。