Instantly share code, notes, and snippets.

# mrocklin/cauchy_characteristic Created Dec 2, 2012

What would you like to do?
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]: 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))⋅ℯ