如何使用SymPy删除高阶术语? .removeO()在这里不起作用。

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

我试图用SymPy绘制一个ODE的序列形式的解决方案,我需要在绘制之前删除'O'项。

from IPython.display import display
from sympy import *
from sympy.plotting import plot

x = Function('x')
t = Symbol('t')
ode = Derivative(x(t),t) + t * x(t) - t**3

sol_series = dsolve(ode, hint='1st_power_series', n=8, ics={x(0): 1})
res = sol_series.removeO()

但是出现了错误

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-66-2775b6fd4150> in <module>
----> 1 res = sol_series.removeO()
      2 display(res)

AttributeError: 'Equality' object has no attribute 'removeO'

如何解决这个问题?

python sympy ode differential-equations
1个回答
1
投票

这是因为从SYMPY.display中返回的 dsolve 是一个 EqremoveO 方法是为了 Expr 所以你应该叫 removeO 在方程的rhs中。

In [5]: res = Eq(sol_series.lhs, sol_series.rhs.removeO())                                                                                                    

In [6]: res                                                                                                                                                   
Out[6]: 
          6      4    2    
         t    3⋅t    t     
x(t) = - ── + ──── - ── + 1
         16    8     2 
© www.soinside.com 2019 - 2024. All rights reserved.