#範例8-4:Euler-Cauchy 方程式之解--複數根 # ode :x**2*y''(x) - x*y'(x) + 4y = 0 #邊界條件或起始條件:y(1) =2, y'(1) =-1 #語法:dsolve(eq, f(x), ics={y(1):2,y(x).diff(x).subs(x,1):-1}) #所解出的原方程式:y(x) = -sin(2*log(x))/2 + 2*cos(2*log(x)) from sympy import * x = symbols('x') y = Function('y') ode = x**2*diff(y(x),x,2) + x*diff(y(x),x) + 4*y(x) ans = dsolve(ode, y(x), ics={y(1):2, y(x).diff(x).subs(x,1):-1}) print('ode的解:', ans.args[0], '=', ans.args[1]) plot(ans.args[1], (x,0,10), line_color='red')