public
Last active

An example using SymPy.stats to compute the characteristic function of a general Cauchy random variable. This is run in isympy (hence the pretty printing).

  • Download Gist
cauchy_characteristic
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
In [1]: from sympy.stats import *
 
In [2]: x0 = Symbol('x0', real=True, bounded=True)
 
In [3]: gamma = Symbol('gamma', positive=True)
 
In [4]: X = Cauchy('X', x0, gamma)
 
In [5]: density(X)(x)
Out[5]:
1
───────────────────
⎛ 2⎞
⎜ (x - x₀) ⎟
π⋅γ⋅⎜1 + ─────────⎟
⎜ 2 ⎟
⎝ γ ⎠
 
In [6]: t = Symbol('t', positive=True)
 
In [7]: E(exp(I*t*X))
Out[7]:
⎛ ⎛ π⎞ ⎛ ⅈ⋅π⎞ ⎞ ⅈ⋅t⋅x₀ ⎛ ⎛ π⎞ ⎛ ⅈ⋅π⎞ ⎞ ⅈ⋅t⋅x₀
⎜2⋅⎜-ⅈ⋅Shi(γ⋅t) - ─⎟⋅cosh(γ⋅t) + 2⋅ⅈ⋅⎜Chi(γ⋅t) - ───⎟⋅sinh(γ⋅t)⎟⋅ℯ ⎜2⋅⎜ⅈ⋅Shi(γ⋅t) - ─⎟⋅cosh(γ⋅t) - 2⋅ⅈ⋅⎜Chi(γ⋅t) + ───⎟⋅sinh(γ⋅t)⎟⋅ℯ
⎝ ⎝ 2⎠ ⎝ 2 ⎠ ⎠ ⎝ ⎝ 2⎠ ⎝ 2 ⎠ ⎠
- ──────────────────────────────────────────────────────────────────────── - ───────────────────────────────────────────────────────────────────────
2⋅π 2⋅π
 
In [8]: simplify(E(exp(I*t*X)))
Out[8]:
ⅈ⋅t⋅x₀
(-sinh(γ⋅t) + cosh(γ⋅t))⋅ℯ

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.