Sympy 微分方程符号解

常微分方程符号解

  • 从数学的角度出发
    • 只支持对形如  y' = f(x, y)
    • f(x, y) 只能是 x(与其指数幂) 与 y(只支持一次) 的非线性组合
  • example
import sympy as sp

# 定义变量
x = sp.symbols("x")
y1 = sp.Function("y1")
y2 = sp.Function("y2")
y3 = sp.Function("y3")


# 定义微分方程组
eq1 = sp.Eq(y1(x).diff(x), 2*y2(x)+x**3-(1+y1(x)))
eq2 = sp.Eq(y2(x).diff(x), 3*x+y1(x)+2+y2(x))
eq3 = sp.Eq(y3(x).diff(x),y2(x))

eq = (eq1, eq2, eq3)
# 求解微分方程组
solution = sp.dsolve(eq)
print(solution)

[Eq(y1(x), C1*(3 - sqrt(3))*exp(sqrt(3)*x) + C2*(sqrt(3) + 3)*exp(-sqrt(3)*x) + x**3/3 - x**2 - 4*x/3 - 7/3), Eq(y2(x), sqrt(3)*C1*exp(sqrt(3)*x) - sqrt(3)*C2*exp(-sqrt(3)*x) - x**3/3 - 5*x/3 - 4/3), Eq(y3(x), C1*exp(sqrt(3)*x) + C2*exp(-sqrt(3)*x) + C3 - x**4/12 - 5*x**2/6 - 4*x/3 - 11/9)]

  • ValueError: dsolve() and classify_ode() only work with functions of one variable, not f(x, y)

    • 只支持解常微分方程(组)

偏微分方程符号解

  • example
import sympy as sp

f = sp.Function("f")
sp.var("x, y, a, b, c")
u = f(x, y)
ux = u.diff(x)
uy = u.diff(y)

eq = a * ux + b * uy + c * u
sp.pprint(eq)
s = sp.pdsolve(eq)
sp.pprint(s)
  ∂               ∂                      
a⋅──(f(x, y)) + b⋅──(f(x, y)) + c⋅f(x, y)
  ∂x              ∂y                     
                         -c⋅(a⋅x + b⋅y) 
                         ───────────────
                              2    2    
                             a  + b     
f(x, y) = F(-a⋅y + b⋅x)⋅ℯ               

你可能感兴趣的:(数学模型与仿真,算法,机器学习,人工智能,数学建模)