Created
December 2, 2012 02:44
-
-
Save mrocklin/4186685 to your computer and use it in GitHub Desktop.
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).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))⋅ℯ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What sympy version do you use? I am trying the same thing but I got
which is not as nice as yours.