Ask Your Question
1

newbie question about symbolic integration in sage

asked 2012-09-22 15:45:33 +0100

kayhan gravatar image

updated 2012-09-22 23:06:33 +0100

kcrisman gravatar image

Hi,

I am new to sage and my question can be naive, I apologize in advance. I would like to use sage for some symbolic integration operations to avoid human mistake. Here is my first test (which is going to important for my application).

Integration of Normal distribution from -infinity to +infinity. Obviously the result should be one and I am wondering why I don't get it:


x, sigma, mu = var('x','sigma','mu')

q = 1/((2*pi)^(1/2)*sigma)*exp(-(x - mu)^2/(2*sigma^2))

show(q)

import sympy

show((sympy.integrate(q, (x,-sympy.oo, sympy.oo))).simplify())

Here is the result:

Integral(2**(1/2)*exp(-mu**2/(2*sigma**2))*exp(-x**2/(2*sigma**2))*exp(mu*x/sigma**2)/(2*pi**(1/2)*sigma),(x,-oo,oo))

I am wondering why I don't get 1? Am I missing anything?

Thanks

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2012-09-22 16:36:35 +0100

achrzesz gravatar image
sage: x, sigma, mu = var('x','sigma','mu')                   
sage: q = 1/((2*pi)^(1/2)*sigma)*exp(-(x - mu)^2/(2*sigma^2))
sage: assume(sigma>0)                                        
sage: integral(q,(x,-oo,oo))                                     
1
edit flag offensive delete link more

Comments

Thank you :) It is true that sign of sigma matters and what you said works and it yields "1". But when I type: integral(-q*log(q),(x,-oo,oo)) to compute entropy. it is still confused about sign of mu ?! even after assuming mu>0 produces stack overflow!

kayhan gravatar imagekayhan ( 2012-09-22 20:25:18 +0100 )edit

Notice that @achrzesz used Maxima's integration (Sage's default integral mode) and not Sympy. Apparently sympy can't do the integral in question, perhaps because of the lack of an assumption framework, who knows...

kcrisman gravatar imagekcrisman ( 2012-09-22 23:09:54 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-09-22 15:45:33 +0100

Seen: 569 times

Last updated: Sep 22 '12