Instantly share code, notes, and snippets.

# mrocklin/t-characteristic Created Dec 2, 2012

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)
 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⎠