r() 函数在 SymPy 的 dsolve 的返回值中是什么意思? [英] What does r() function mean in the return value of SymPy's dsolve?

查看:131
本文介绍了r() 函数在 SymPy 的 dsolve 的返回值中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想评估 phi(+oo) 的值其中phi(xi)是ODE的解

I want to evaluate the value of phi(+oo) where phi(xi) is the solution of ODE

Eq(Derivative(phi(xi), (xi, 2)), (-K + xi**2)*phi(xi))

K 是一个已知的实变量.通过dsolve,我得到了解决方案:

and K is a known real variable. By dsolve, I got the solution:

Eq(phi(xi), -K*xi**5*r(3)/20 + C2*(K**2*xi**4/24 - K*xi**2/2 + xi**4/12 + 1) + C1*xi*(xi**4/20 + 1) + O(xi**6))

在右侧的第一项中具有未知函数 r().这是我的代码:

with an unknown function r() in the first term on the right-hand side. Here is my code:

import numpy as np
import matplotlib.pyplot as plt
import sympy
from sympy import I, pi, oo

sympy.init_printing()

def apply_ics(sol, ics, x, known_params):
    """
    Apply the initial conditions (ics), given as a dictionary on
    the form ics = {y(0): y0, y(x).diff(x).subs(x, 0): yp0, ...},
    to the solution of the ODE with independent variable x.
    The undetermined integration constants C1, C2, ... are extracted
    from the free symbols of the ODE solution, excluding symbols in
    the known_params list.
    """

    free_params = sol.free_symbols - set(known_params)
    eqs = [(sol.lhs.diff(x, n) - sol.rhs.diff(x, n)).subs(x, 0).subs(ics)
            for n in range(len(ics))]
    sol_params = sympy.solve(eqs, free_params)

    return sol.subs(sol_params)

K = sympy.Symbol('K', positive = True)
xi = sympy.Symbol('xi',real = True)
phi = sympy.Function('phi')
ode = sympy.Eq( phi(xi).diff(xi, 2), (xi**2-K)*phi(xi))

ode_sol = sympy.dsolve(ode)
ics = { phi(0):1, phi(xi).diff(xi).subs(xi,0): 0}
phi_xi_sol = apply_ics(ode_sol, ics, xi, [K])

其中ode_sol 是解,phi_xi_sol 是应用初始条件后的解.由于 r() 在 NumPy 中未定义,我无法通过

Where ode_sol is the solution, phi_xi_sol is the solution after initial conditions are applied. Since r() is undefined in NumPy I can't evaluate the results by

for g in [0.9, 0.95, 1, 1.05, 1.2]:
    phi_xi = sympy.lambdify(xi, phi_xi_sol.rhs.subs({K:g}), 'numpy')

有谁知道这个函数 r() 是什么意思,我应该如何处理?

Does anyone know what this function r() mean and how should I deal with it?

推荐答案

从结果的形式可以看出,求解器回退到幂级数解(而不是像 WolframAlpha 那样根据抛物线圆柱函数搜索解)).

As visible in the form of the result, the solver falls back to a power series solution (instead of searching the solution in terms of parabolic cylinder functions as WolframAlpha does).

所以让我们设置 phi(xi)=sum a[k]*xi^k 导致系数方程(使用 a[k]=0 for k<0)

So let's set phi(xi)=sum a[k]*xi^k leading to the coefficient equations (using a[k]=0 for k<0)

(k+2)(k+1)a[k+2] = -K*a[k] + a[k-2]

a[0] = C2  
a[1] = C1  
a[2] = -K/2*C2
a[3] = -K/6*C1
a[4] = (K^2/2 + 1)/12*C2
a[5] = (K^2/6 + 1)/20*C1

插入幂级数解应该是

C2*(1-K/2*xi**2+(K**2/24+1/12)*xi**4) + C1*xi*(1-K/6*xi**2+(K/120+1/20)*xi**4) + O(xi**6)

与sympy解相比,所有同时包含C1K的词条都缺失了,尤其是缺失度3的词条无法解释.似乎求解过程过早结束,或者某些方程变换没有正确反转.

Comparing with the sympy solution, all terms containing both C1 and K are missing, especially the missing degree 3 term is not explainable. It seems that the solution process was prematurely ended, or some equation transformation was not correctly reversed.

请注意,sympy 中的 ODE 求解器例程是实验性的和基本的.此外,幂级数解决方案仅提供 xi 的小值的有效信息,无法推导出 +oo 处极限的任何精确值.

Please note that the ODE solver routines in sympy are experimental and rudimentary. Also, the power series solution gives only valid information for small values of xi, there is no way to derive any exact value for the limit at +oo.

这篇关于r() 函数在 SymPy 的 dsolve 的返回值中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆