Thanks! This works great. On Tuesday, July 15, 2014 2:28:11 PM UTC-7, Matthew wrote: > > Use sympy.stats, not sympy.statistics > > In [1]: x, mu = symbols('x,mu', real=True) > > In [2]: sigma = symbols('sigma', positive=True) > > In [3]: from sympy.stats import * > > In [4]: X = Normal('X', mu, sigma) > > In [5]: moment? > Type: function > String form: <function moment at 0x7fc3fbbe2b18> > File: /home/mrocklin/workspace/sympy/sympy/stats/rv_interface.py > Definition: moment(X, n, c=0, condition=None, **kwargs) > Docstring: > Return the nth moment of a random expression about c i.e. E((X-c)**n) > Default value of c is 0. > > Examples > ======== > > >>> from sympy.stats import Die, moment, E > >>> X = Die('X', 6) > >>> moment(X, 1, 6) > -5/2 > >>> moment(X, 2) > 91/6 > >>> moment(X, 1) == E(X) > True > > In [6]: moment(X, 1) > Out[6]: μ > > In [7]: moment(X, 2) > Out[7]: > 2 2 > μ + σ > > In [8]: moment(X, 3) > Out[8]: > 3 2 > μ + 3⋅μ⋅σ > > In [9]: moment(X, 4) > Out[9]: > 4 2 2 4 > μ + 6⋅μ ⋅σ + 3⋅σ > > > > On Tue, Jul 15, 2014 at 1:40 PM, Justin Vincent <just...@gmail.com > <javascript:>> wrote: > >> Wanted to get the moments of a Normal distribution WRT mu and sigma, a la: >> >> http://en.wikipedia.org/wiki/Normal_distribution#Moments >> >> For starters, this outputs 1 for one for one crazy domains, and then >> leaves the integral unevaluated on the rest of the domain. But it gets one, >> so I'm cool with that. >> >> from sympy.statistics import Normal >> from sympy import symbols, integrate >> f = Normal(mu, sigma).pdf(x) >> x, mu, sigma = symbols('x mu sigma') >> integrate(f, (x,-oo, oo)) >> >> Then when I get the first moment, it really starts to go crazy though, >> and leaves it all indefinite: >> integrate(f * x, (x, -oo, oo)) >> >> What approach should I take here if I wanted to get those values cited in >> wikipedia? Haven't used Sympy much before. Thanks in advance. >> >> Justin >> >> -- >> You received this message because you are subscribed to the Google Groups >> "sympy" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to sympy+un...@googlegroups.com <javascript:>. >> To post to this group, send email to sy...@googlegroups.com <javascript:> >> . >> Visit this group at http://groups.google.com/group/sympy. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/sympy/2babc41b-0ab4-443c-a75b-d5910ce16c21%40googlegroups.com >> >> <https://groups.google.com/d/msgid/sympy/2babc41b-0ab4-443c-a75b-d5910ce16c21%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > >
-- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sympy+unsubscr...@googlegroups.com. To post to this group, send email to sympy@googlegroups.com. Visit this group at http://groups.google.com/group/sympy. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/9aee387b-ccc9-41a1-b963-af3de0f87557%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.