我想先用微分方程隐式定义形式幂级数的几个系数。
Example.
import sympy as sp
sp.init_printing() # math as latex
from IPython.display import display
z = sp.Symbol('z')
F = sp.Function('F')(z)
F_ = sp.Derivative(F, z)
equation = sp.Eq(F**2 + 1 - F_, 0)
display(equation)
solution = sp.dsolve(equation)
display(solution)
sp.series(sp.tan(z), n = 8)
Question. How to compute formal power series solution of ODE without explicitly solving it in terms of elementary functions?
Sidenote. Some differential equations (even linear) have solutions in divergent power series only, for example an equation
L = z^2 + z^2 L + z^4 L'
. It is interesting to know whethersympy
supports such equations along with usual ones.
相关。
当前问题是一个更简单问题的续集。
Sympy: how to solve algebraic equation in formal power series?
最佳答案
更新:已发布类似问题的答案here .我使用第二个答案而不是下面给出的答案。使用 sympy 标准函数的解决方案运行速度非常慢。
这在 sympy-1.1.1
中似乎(部分)可行。请务必先更新到相应的版本。我引用了官方文档关于常微分方程的部分
http://docs.sympy.org/latest/modules/solvers/ode.html
我们可以使用方法 dsolve
和额外的提示,要求将解决方案表示为正式的幂级数。这仅适用于某些类型的方程式。对于上面的等式,我们要求可能的提示类型。
>>> sp.classify_ode(equation)
('separable',
'1st_exact',
'1st_power_series',
'lie_group',
'separable_Integral',
'1st_exact_Integral')
继续问题中的示例,我们指定提示 '1st_power_series'
和初始条件 F(0) = 0
:
solution = sp.dsolve(equation, hint='1st_power_series', ics={F.subs(z,0):0})
display(solution)
Issue 1. If we want more terms, even say
n = 10
, the function works for a very long time (normally, I expect 20 coefficients within several seconds). Combinatorially, one can write a very fast recurrence for linear ODE. I don't know whether it is implemented insympy
.Issue 2. This technique doesn't seem to apply to Ricatti equations like the one mentioned in the original question
L = z^2 + z^2 L + z^4 L'
.
如果有人知道更好的解决方案,热烈欢迎他!
关于sympy - 如何求解形式幂级数的微分方程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46427586/