1、对于一个微分方程,使用MATLAB可以很轻松得到其解析解,但是使用Python的sympy库却返回一个空列表。
2、
MATLAB代码如下:
clear;
clc;
syms T(x) x m n q A;
x1 = 339.5;
x2 = 410.5;
T1 = 255;
T2 = 25;
m=2.4772
n = 0.0071
q = (m+n*(T2+T1)/2)*((T2-T1)/(x2-x1))
e = diff(T,x) == q/(m+n*T(x)); %待求解方程
cond = [T(x1)==T1]; %边界条件
T = dsolve(e,cond)
结果
T =
(2^(1/2)*(7259410169/2 - 7983760*x)^(1/2))/71 - 24772/71
Python代码如下
import sympy as sy
def solveequ(x1,x2,T1,T2,m=2.4772,n=0.0071):
T_e = sy.symbols('T_e', cls=sy.Function)
x = sy.symbols("x")
Q = ((T2-T1)/(x2-x1))*(m+n*(T2+T1)/2)
eq = sy.Eq((m+n*T_e(x))*T_e(x).diff(x),Q)
edge = {}
edge[T_e(x1)] = T1
getT = sy.dsolve(eq,T_e(x), ics=edge)
return getT
T0 = 25
T1 = 175
T2 = 195
T3 = 235
T4 = 255
T_e = solveequ(339.5,410.5,T4,T0)
[]