You could try doing this : >>> x,k=symbols('xk') >>> f= lambda n : Integral(x**k*exp(-x),(x,0,oo)).subs(k,n) >>> f(2) Integral(x**2*exp(-x), (x, 0, oo)) >>> f(2).doit() 2
This works only for integers, for real n, try making use of quad in scipy - and libmpf (?). On Apr 18, 5:53 am, Minjae Kim <the.min...@gmail.com> wrote: > Hello, > n is a symbol, so I was expecting a function of n as the result. > (By the way, changing '10' to 'oo' would have been more relevant: a mistake > on my part) > > integrate(exp(-x)*x**n, (x,0,oo)) > > Which still fails. > > Thanks for your point about evalf(). > > Best, > Minjae > > On Fri, Apr 17, 2009 at 8:07 PM, Ondrej Certik <ond...@certik.cz> wrote: > > > On Fri, Apr 17, 2009 at 4:02 PM, Minjae <the.min...@gmail.com> wrote: > > > > Hello, > > > > I am very new to Sympy, and I was attempting to use it in place of > > > Mathematica. It seems that when I try to integrate > > > > integrate(exp(-x)*x**n,(x,0,10)).evalf() > > > is "n" a number? If so, it works for me: > > > In [5]: integrate(exp(-x)*x**4, (x,0,10)) > > Out[5]: > > -10 > > 24 - 15464⋅ℯ > > > if it's a symbol, then I think we can't do it yet, I made it: > > >http://code.google.com/p/sympy/issues/detail?id=1388 > > > Btw, the .evalf() is for numerical evaluation, so that would fail in > > any way if you have some symbols in the expression. > > > Ondrej > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to sympy@googlegroups.com To unsubscribe from this group, send email to sympy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sympy?hl=en -~----------~----~----~----~------~----~------~--~---