如何在 SymPy 中按预期求解这个微分方程 (1-x^2)y'=x^2-xy-1?

问题描述 投票:0回答:1

我想用 Sympy 求解 (1-x^2)y'=x^2-xy-1 ,但无法按预期求解。 我希望得到以下解决方案。

-1<x<1:y(x)=-sqrt(1-x**2)*asin(x)+C1*sqrt(1-x**2)
x<-1,x>1:y(x)=-sqrt(x**2-1)*log(abs(x+sqrt(x**2-1)))+C1*sqrt(x**2-1)
x=0:y=0

但据我尝试,我无法得到这个答案。 我该怎么做?

在 Sympy 中,我运行了以下代码并得到了以下输出。

x, C1= symbols("x, C1")
y = symbols('y',cls=Function)
eq=Eq((1-x**2)*Derivative(y(x),x),x**2-x*y(x)-1)
sols = dsolve(eq,y(x),hint='all')
exp_fin=False
for k,v in sols.items():
  if k=="best":
    exp_fin=True
    continue
  print("--------------------------------")
  print(k)
  display(v if exp_fin else v.doit())

enter image description here

enter image description here

enter image description here

在我的研究中我发现(https://www.symbolab.com/)可以找到-1的预期解决方案

如果我正确理解,这段代码就可以了。`import sympy as sp

定义符号

x, C1 = sp.symbols('x C1')

定义分段函数

y = sp.Piecewise((-sp.sqrt(1 - x2) * sp.asin(x) + C1 * sp.sqrt(1 - x2), (x > -1) & (x < 1)),
) (-sp.sqrt(x2 - 1) * sp.log(sp.Abs(x + sp.sqrt(x2 - 1))) + C1 * sp.sqrt(x**2 - 1), (x < -1) | (x > 1)),
(0, x == 0))

打印分段函数

sp.pprint(y)在此处输入图像描述`

python math sympy ode differential-equations
1个回答
0
投票
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.