文章目录
- 简介
- SingularityFunction
- rewrite
简介
奇异函数是一类不连续函数,可用麦考利括号表示为
f ( t ) = < t − t 0 > n f(t)=\lt t-t_0\gt^n f(t)=<t−t0>n
当 n < 0 n\lt 0 n<0时,记 N = − n − 1 ≥ 0 N=-n-1\geq0 N=−n−1≥0,奇异函数可表示为Dirac函数的导数 d N δ ( t − t 0 ) d t N \frac{\text d^N\delta(t-t_0)}{\text dt^N} dtNdNδ(t−t0)。特别地,当 n = − 1 n=-1 n=−1时, N = 0 N=0 N=0,则奇异函数等价于Dirac函数 δ ( t − t 0 ) \delta(t-t_0) δ(t−t0)。
当 n ≥ 0 n\geq 0 n≥0时,可用阶跃函数表示 ( t − t 0 ) n θ ( t − t 0 ) (t-t_0)^n\theta(t-t_0) (t−t0)nθ(t−t0),当 n = 0 n=0 n=0时,奇异函数即等于阶跃函数 θ ( t − t 0 ) \theta(t-t_0) θ(t−t0)。
SingularityFunction
sympy中实现了奇异函数,有三个输入参数,依次表示公式中的 t , t 0 , n t, t_0, n t,t0,n
SingularityFunction(variable, offset, exponent)
由于当 n = − 1 n=-1 n=−1时,奇异函数等价于狄拉克函数,下面做一个测试
from sympy import SingularityFunctionfor t in range(10):s = SingularityFunction(t,2,-1)print(f"f({t},2,-1)={s}")
由其输出可知,只有当 t = 2 t=2 t=2时, f ( 2 , 2 , − 1 ) = o o f(2,2,-1)=oo f(2,2,−1)=oo,否则均为0。
若取 n = 0 n=0 n=0,则奇异函数等价于阶跃函数,示例如下
from sympy.abc import x, a, n, plots = SingularityFunction(x,2,0)
plot(s, xlim=(-5,5), ylim=(0,2))
rewrite
考虑到奇异函数和Dirac函数、阶跃函数的密切关系,SingularityFunction内置了rewrite方法,可用这两个函数来重新表达
from sympy import print_latex
expr = SingularityFunction(x, a, 5)
print_latex(expr)
print_latex(expr.rewrite(Heaviside))
打印结果如下
- ⟨ − a + x ⟩ 5 {\left\langle - a + x \right\rangle}^{5} ⟨−a+x⟩5
- ( − a + x ) 5 θ ( − a + x ) \left(- a + x\right)^{5} \theta\left(- a + x\right) (−a+x)5θ(−a+x)
若 n < 0 n<0 n<0,则示例如下
expr = SingularityFunction(x, a, -2)
print_latex(expr)
print_latex(expr.rewrite(DiracDelta))
- ⟨ − a + x ⟩ − 2 {\left\langle - a + x \right\rangle}^{-2} ⟨−a+x⟩−2
- − δ ( 1 ) ( a − x ) - \delta^{\left( 1 \right)}\left( a - x \right) −δ(1)(a−x)