如何求解多个常微分方程?sympy.dsolve返回相同的积分常量,所以我无法解决它。
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
from sympy.interactive import printing
printing.init_printing(use_latex=True)
from sympy import *
x,l,F,k_0,q_0,n,a,C1,C2,C3,C4,Φ1,Φ2,D1,D2=symbols('x l F k_0 q_0 n a C1 C2 C3 C4 Φ_1 Φ_2 D1 D2')
n=5
q=0
k1=k_0
k2=n*k_0
eq1=Function('eq1')(x)
eq2=Function('eq2')(x)
w1=dsolve(k1.diff(x)*eq1.diff(x)+k1*eq1.diff(x,2)+q).rhs
w2=dsolve(k2.diff(x)*eq2.diff(x)+k2*eq2.diff(x,2)+q).rhs
display(w1)
display(w2)
代码返回:
C1+C2*x
C1+C2*x
虽然我想要这样的东西:
C1+C2*x
C3+C4*x
我发现这是一个答案,但也许有一些更简单的东西
char='D'
diff=k2.diff(x)*eq2.diff(x)+k2*eq2.diff(x,2)+q
def ODE(diff,char):
func=dsolve(diff).rhs
for i in range(1,len(func.free_symbols)):
old=symbols('C{}'.format(i))
new=symbols(char + '{}'.format(i))
func=func.subs(old,new)
return func
w2=ODE(diff,char)
display(w2)