常微分方程符号解

  • 从数学的角度出发
    • 只支持对形如  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)

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

08-30 03:11