我想用 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())
在我的研究中我发现(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)在此处输入图像描述`