Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

The pdf of a half normal distribution is: $\frac{\sqrt{2}}{\sigma\sqrt{\pi}}\exp\left(-\frac{x^2}{2\sigma^2}\right)$, $x>0$

$$\int_{0}^{\infty}\frac{\sqrt{2}}{\sigma\sqrt{\pi}}\exp\left(-\frac{x^2}{2\sigma^2}\right)\mathrm{d}x=\frac{1}{\sqrt{\sigma}}$$

This doesn't make sense, the integral should be equal to one, right?

Mathematica code used to compute this:

Integrate[(Sqrt[2/Pi]/s)*Exp[-(x^2)/(2*s^2)], {x, 0, Infinity}, Assumptions -> Re[s^2] > 0]

What am I doing wrong?

share|improve this question

migrated from math.stackexchange.com Apr 14 at 5:35

This question came from our site for people studying math at any level and professionals in related fields.

1  
And it is equal to $1$. –  André Nicolas Apr 14 at 3:33
    
See the Mathematica code I added to the question. –  user142972 Apr 14 at 3:48
    
Luckily not my problem, I can't afford Mathematica. Conceivably a bug. More likely an input typo. –  André Nicolas Apr 14 at 4:22
add comment

2 Answers 2

Using Assuming[Element[s, Reals] && s > 0 tells Mathematica that Re[s^2]>1 and also s itself is real to allow it to simplify final result to 1.

Mathematica did not simplify $\sqrt{\frac{1}{s^2}}$ to $\frac{1}{s}$ since it did not know if $s$ was real or not and if it was real, if it is positive or not. That is why you did not get the result 1 expected.

Assuming[Element[s, Reals] && s > 0, Integrate[(Sqrt[2/Pi]/s)*Exp[-(x^2)/(2*s^2)], 
     {x, 0, Infinity}]]

 (* 1*)
share|improve this answer
    
thanks this is the right answer, but for this OP, it might be helpful to provide a bit more textual explanation. –  Verbeia Apr 14 at 6:19
add comment

Here are some variants:

td = TruncatedDistribution[{0, Infinity}, NormalDistribution[0, s]];
Assuming[Element[s, Reals] && s > 0, 
Integrate[Sqrt[2/Pi] Exp[-x^2/(2 s^2)]/s, {x, 0, Infinity}]]
Integrate[Sqrt[2/Pi] Exp[-x^2/(2 s^2)]/s, {x, 0, Infinity}, 
 Assumptions -> {Element[s, Reals], s > 0}]
Integrate[PDF[td, x], {x, 0, Infinity}, 
 Assumptions -> {Element[s, Reals], s > 0}]
Integrate[
 PDF[HalfNormalDistribution[Sqrt[2/Pi]/s], x], {x, 0, Infinity}, 
 Assumptions -> {Element[s, Reals], s > 0}]

Note all the integrals yield 1. As @Nasser has observed the assumptions need to be declared.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.