关于完整函数的操作¶
加法和乘法¶
两个全纯函数可以相加或相乘,结果仍然是一个全纯函数。
>>> from sympy.holonomic.holonomic import HolonomicFunction, DifferentialOperators >>> from sympy.polys.domains import QQ >>> from sympy import symbols >>> x = symbols('x') >>> R, Dx = DifferentialOperators(QQ.old_poly_ring(x),'Dx')
p
和q
在这里分别是 \(e^x\) 和 \(\sin(x)\) 的完整表示。>>> p = HolonomicFunction(Dx - 1, x, 0, [1]) >>> q = HolonomicFunction(Dx**2 + 1, x, 0, [0, 1])\(e^x+\sin(x)\) 的完整表示
>>> p + q HolonomicFunction((-1) + (1)*Dx + (-1)*Dx**2 + (1)*Dx**3, x, 0, [1, 2, 1])\(e^x \cdot \sin(x)\) 的完整表示
>>> p * q HolonomicFunction((2) + (-2)*Dx + (1)*Dx**2, x, 0, [0, 1])
积分与微分¶
- HolonomicFunction.integrate(
- limits,
- initcond=False,
积分给定的全纯函数。
示例
>>> from sympy.holonomic.holonomic import HolonomicFunction, DifferentialOperators >>> from sympy import QQ >>> from sympy import symbols >>> x = symbols('x') >>> R, Dx = DifferentialOperators(QQ.old_poly_ring(x),'Dx') >>> HolonomicFunction(Dx - 1, x, 0, [1]).integrate((x, 0, x)) # e^x - 1 HolonomicFunction((-1)*Dx + (1)*Dx**2, x, 0, [0, 1]) >>> HolonomicFunction(Dx**2 + 1, x, 0, [1, 0]).integrate((x, 0, x)) HolonomicFunction((1)*Dx + (1)*Dx**3, x, 0, [0, 1, 0])
- HolonomicFunction.diff(*args, **kwargs)[源代码][源代码]¶
给定Holonomic函数的微分。
参见
示例
>>> from sympy.holonomic.holonomic import HolonomicFunction, DifferentialOperators >>> from sympy import ZZ >>> from sympy import symbols >>> x = symbols('x') >>> R, Dx = DifferentialOperators(ZZ.old_poly_ring(x),'Dx') >>> HolonomicFunction(Dx**2 + 1, x, 0, [0, 1]).diff().to_expr() cos(x) >>> HolonomicFunction(Dx - 2, x, 0, [1]).diff().to_expr() 2*exp(2*x)
多项式组合¶
- HolonomicFunction.composition(
- expr,
- *args,
- **kwargs,
返回一个全纯函数与一个代数函数复合后的函数。该方法无法自行计算结果的初始条件,因此也可以提供这些条件。
参见
示例
>>> from sympy.holonomic.holonomic import HolonomicFunction, DifferentialOperators >>> from sympy import QQ >>> from sympy import symbols >>> x = symbols('x') >>> R, Dx = DifferentialOperators(QQ.old_poly_ring(x),'Dx') >>> HolonomicFunction(Dx - 1, x).composition(x**2, 0, [1]) # e^(x**2) HolonomicFunction((-2*x) + (1)*Dx, x, 0, [1]) >>> HolonomicFunction(Dx**2 + 1, x).composition(x**2 - 1, 1, [1, 0]) HolonomicFunction((4*x**3) + (-1)*Dx + (x)*Dx**2, x, 1, [1, 0])
转换为全向序列¶
- HolonomicFunction.to_sequence(lb=True)[源代码][源代码]¶
找到函数在 \(x_0\) 处展开的级数中系数的递推关系,其中 \(x_0\) 是存储初始条件的点。
参考文献
示例
>>> from sympy.holonomic.holonomic import HolonomicFunction, DifferentialOperators >>> from sympy import QQ >>> from sympy import symbols, S >>> x = symbols('x') >>> R, Dx = DifferentialOperators(QQ.old_poly_ring(x),'Dx') >>> HolonomicFunction(Dx - 1, x, 0, [1]).to_sequence() [(HolonomicSequence((-1) + (n + 1)Sn, n), u(0) = 1, 0)] >>> HolonomicFunction((1 + x)*Dx**2 + Dx, x, 0, [0, 1]).to_sequence() [(HolonomicSequence((n**2) + (n**2 + n)Sn, n), u(0) = 0, u(1) = 1, u(2) = -1/2, 2)] >>> HolonomicFunction(-S(1)/2 + x*Dx, x, 0, {S(1)/2: [1]}).to_sequence() [(HolonomicSequence((n), n), u(0) = 1, 1/2, 1)]
级数展开¶
- HolonomicFunction.series(
- n=6,
- coefficient=False,
- order=True,
- _recur=None,
找到给定holonomic函数在 \(x_0\) 处的幂级数展开。
示例
>>> from sympy.holonomic.holonomic import HolonomicFunction, DifferentialOperators >>> from sympy import QQ >>> from sympy import symbols >>> x = symbols('x') >>> R, Dx = DifferentialOperators(QQ.old_poly_ring(x),'Dx') >>> HolonomicFunction(Dx - 1, x, 0, [1]).series() # e^x 1 + x + x**2/2 + x**3/6 + x**4/24 + x**5/120 + O(x**6) >>> HolonomicFunction(Dx**2 + 1, x, 0, [0, 1]).series(n=8) # sin(x) x - x**3/6 + x**5/120 - x**7/5040 + O(x**8)
数值评估¶
- HolonomicFunction.evalf(
- points,
- method='RK4',
- h=0.05,
- derivatives=False,
使用数值方法找到一个完整函数的数值(默认使用RK4方法)。必须提供一组点(实数或复数),这些点将作为数值积分的路径。
示例
>>> from sympy.holonomic.holonomic import HolonomicFunction, DifferentialOperators >>> from sympy import QQ >>> from sympy import symbols >>> x = symbols('x') >>> R, Dx = DifferentialOperators(QQ.old_poly_ring(x),'Dx')
实轴上从 (0 到 1) 的一条直线
>>> r = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1]
从0.1到1的e^x上的Runge-Kutta四阶方法。在1处的精确解是2.71828182845905。
>>> HolonomicFunction(Dx - 1, x, 0, [1]).evalf(r) [1.10517083333333, 1.22140257085069, 1.34985849706254, 1.49182424008069, 1.64872063859684, 1.82211796209193, 2.01375162659678, 2.22553956329232, 2.45960141378007, 2.71827974413517]
欧拉方法用于相同的情况
>>> HolonomicFunction(Dx - 1, x, 0, [1]).evalf(r, method='Euler') [1.1, 1.21, 1.331, 1.4641, 1.61051, 1.771561, 1.9487171, 2.14358881, 2.357947691, 2.5937424601]
还可以观察到,使用四阶龙格-库塔法得到的值比欧拉法要精确得多。
转换为超几何函数的线性组合¶
- HolonomicFunction.to_hyper(
- as_list=False,
- _recur=None,
返回一个超几何函数(或它们的线性组合),表示给定的正合函数。
示例
>>> from sympy.holonomic.holonomic import HolonomicFunction, DifferentialOperators >>> from sympy import ZZ >>> from sympy import symbols >>> x = symbols('x') >>> R, Dx = DifferentialOperators(ZZ.old_poly_ring(x),'Dx') >>> # sin(x) >>> HolonomicFunction(Dx**2 + 1, x, 0, [0, 1]).to_hyper() x*hyper((), (3/2,), -x**2/4) >>> # exp(x) >>> HolonomicFunction(Dx - 1, x, 0, [1]).to_hyper() hyper((), (), x)
转换为 Meijer G-函数的线性组合¶
- HolonomicFunction.to_meijerg()[源代码][源代码]¶
返回一个 Meijer G-函数的线性组合。
参见
示例
>>> from sympy.holonomic import expr_to_holonomic >>> from sympy import sin, cos, hyperexpand, log, symbols >>> x = symbols('x') >>> hyperexpand(expr_to_holonomic(cos(x) + sin(x)).to_meijerg()) sin(x) + cos(x) >>> hyperexpand(expr_to_holonomic(log(x)).to_meijerg()).simplify() log(x)
转换为表达式¶
- HolonomicFunction.to_expr()[源代码][源代码]¶
将一个全纯函数转换回初等函数。
示例
>>> from sympy.holonomic.holonomic import HolonomicFunction, DifferentialOperators >>> from sympy import ZZ >>> from sympy import symbols, S >>> x = symbols('x') >>> R, Dx = DifferentialOperators(ZZ.old_poly_ring(x),'Dx') >>> HolonomicFunction(x**2*Dx**2 + x*Dx + (x**2 - 1), x, 0, [0, S(1)/2]).to_expr() besselj(1, x) >>> HolonomicFunction((1 + x)*Dx**3 + Dx**2, x, 0, [1, 1, 1]).to_expr() x*log(x + 1) + log(x + 1) + 1