# simplifying an expectation with the normal law

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)
show((integrate(g(x),(x,-oo,oo)).full_simplify()))
show(integrate(g(x),(x,-oo,oo)).full_simplify().subs({sqrt(s^2):s}).subs({sqrt(s^2):s}))

edit retag close merge delete

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

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

Sort by » oldest newest most voted

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 ?

BTW :

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...

more

yes thanks

( 2020-11-29 13:23:03 +0200 )edit