Ask Your Question

simplifying an expectation with the normal law

asked 2020-11-29 12:13:42 +0200

Cyrille gravatar image

Just for the fun (since I can find the good result), why am I obliged to help so much Sagemath toç gpo through the last steps of this integration for so elementary evidence ?

var("a x s m")
f(x) = - exp(- a*x)
p(x) = (1/ (sqrt(2*pi)*s))*exp(- (1/2)*((x-m)/s)^2)
g(x) = f(x)*p(x)
edit retag flag offensive close merge delete


Typo: "toç gpo" -> "to go".

slelievre gravatar imageslelievre ( 2020-11-29 15:45:44 +0200 )edit

1 Answer

Sort by » oldest newest most voted

answered 2020-11-29 13:18:14 +0200

Emmanuel Charpentier gravatar image

Is this :

sage: integrate(g(x),(x,-oo,oo)).full_simplify().canonicalize_radical()         
-e^(1/2*a^2*s^2 - a*m)

what you want ?


sage: assume (a, m, x, "real")                                                  
sage: assume(s>0)                                                               
sage: assumptions()                                                             
[a is real, m is real, x is real, s > 0]
sage: integrate(g(x),(x,-oo,oo)).full_simplify()                                
-e^(1/2*a^2*s^2 - a*m)
sage: integrate(g(x),(x,-oo,oo)).simplify()                                     
-e^(1/2*a^2*s^2 - a*m)

In integration, assumptions may be capital...

edit flag offensive delete link more


yes thanks

Cyrille gravatar imageCyrille ( 2020-11-29 13:23:03 +0200 )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

1 follower


Asked: 2020-11-29 12:13:42 +0200

Seen: 117 times

Last updated: Nov 29 '20