#範例7-2:微分方程式ODE求解,y'(x) = x**3+1, 邊界條件:y(0)=3 #微分方程式:y'(x) = x**3+1 #邊界條件是: y(0)=3 #原始方程式: y(x) = x**4 + x + 3 #降階,微分方程式ODE, y'(x) = x**3+1 #語法:dsolve(eq, f(x), ics={y(0):3}) from sympy import * x = symbols('x') y = Function('y')(x) #注意:ode是個方程式,不是函數 ode = Eq(y.diff(x), x**3 +1) #from ode to find the 原始函數 y(x) ans = dsolve(ode,y,ics={y.subs(x,0):3}) print('求出解:',ans.args[0],' = ', ans.args[1]) #畫出y(x) f = ans.args[1] #plot(f) plot(f,(x,-4,4))