gpt4 book ai didi

python - 如何修复/解决 sympy dsolve 函数中的 NotImplemented 错误?

转载 作者:太空宇宙 更新时间:2023-11-03 21:04:28 24 4
gpt4 key购买 nike

我尝试在 sympy 中求解 4 个微分方程组。我收到“NotImplementedError”。有解决办法吗?

我试图解决的颂歌集是:

![ODE]: /image/2U4BR.jpg

我尝试用数值替换 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”

最佳答案

您创建方程的语法不正确。 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 可能可以在这里改进。用数字参数替换符号参数应该会使速度更快。

关于python - 如何修复/解决 sympy dsolve 函数中的 NotImplemented 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55516346/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com