sympy - 如何求解形式幂级数的微分方程?

标签 sympy

我想先用微分方程隐式定义形式幂级数的几个系数。

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)

enter image description here

solution = sp.dsolve(equation)
display(solution)

enter image description here

sp.series(sp.tan(z), n = 8)

enter image description here

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 whether sympy 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)

enter image description here

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 in sympy.

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/

相关文章:

python - 检查 Sympy Expression 是否为 Nan?

python - 用 SymPy 求解微分方程

python - 没有名为 statistics.distributions 的模块

python - sympy.physical.units 替换给出 TypeError

python - 在 ipython 中 latex 打印继承的 sympy 类时行为不一致

python - sin(y) 导致 "can' t 将表达式转换为 float"错误

python-2.7 - 无法区分 python 中的变量

python - odeint() 中的 Sympy 表达式给出推导错误

python-3.x - 来自part()的部分分数

python - 在 sympy Latex 中将系数渲染为分数