public
Created

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
t-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 33
In [1]: from sympy.stats import *
 
In [2]: nu = Symbol("nu", positive=True)
 
In [3]: X = StudentT("x", nu)
 
In [4]: density(X)(x)
Out[4]:
ν 1
- ─ - ─
2 2
⎛ 2⎞
⎜ x ⎟ ⎛ν 1⎞
⎜1 + ──⎟ ⋅Γ⎜─ + ─⎟
⎝ ν ⎠ ⎝2 2⎠
────────────────────────
___ ___ ⎛ν⎞
╲╱ π ⋅╲╱ ν ⋅Γ⎜─⎟
⎝2⎠
 
In [5]: t = Symbol('t', positive=True)
 
In [6]: simplify(E(exp(I*t*X)))
Out[6]:
ν ν ⎛ ⅈ⋅π⋅ν ⎞ -ⅈ⋅π⋅ν
─ - 1 ⎛4 ___ ___⎞ ⎜ ───── ⎟ ──────
2 ⎜╲╱ ν ⋅╲╱ t ⎟ ⎜ ν 2 ⎛π⋅ν⎞ ⎛-ν ___ ⎞ ν ⅈ⋅π⋅ν ⎛ν ___ ⎞ ν ⎛ν ___ ⎞⎟ 2
2 ⋅π⋅⎜───────────⎟ ⋅⎜2⋅4 ⋅ℯ ⋅cos⎜───⎟⋅besseli⎜──, ╲╱ ν ⋅t⎟ - 4 ⋅ℯ ⋅besseli⎜─, ╲╱ ν ⋅t⎟ - 4 ⋅besseli⎜─, ╲╱ ν ⋅t⎟⎟⋅ℯ
⎝ 8 ⎠ ⎝ ⎝ 2 ⎠ ⎝2 ⎠ ⎝2 ⎠ ⎝2 ⎠⎠
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
⎛π⋅ν⎞ ⎛π⋅ν⎞ ⎛ν⎞
sin⎜───⎟⋅cos⎜───⎟⋅Γ⎜─⎟
⎝ 2 ⎠ ⎝ 2 ⎠ ⎝2⎠

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.