# What's wrong with my calculation of the expectation of the Laplace distribution?

f2[x_, mu2_, sigma2_] =  1/Sqrt[2*sigma2^2]*Exp[-Sqrt*Abs[(x - mu2)/sigma2]]

Integrate[x*f2[x, mu, sigma], {x, -Infinity, Infinity},  Assumptions -> sigma > 0]


I am pretty sure that the above should produce mu, but it doesn't. What's wrong with it? I did the same thing in Sage, and it worked all right.

• Just who is "Lacplac"? May 7 '13 at 4:08
• @J.M. A friend of mine gador.com.ar/?cont=prod&id=552 May 7 '13 at 4:12
• @bel, your friend makes me sleepy. May 7 '13 at 4:14
• @J.M. Sorry to spoil the joke with my edit, but I felt I had a duty to posterity. May 7 '13 at 4:18
• @m_goldberg, no worries, and thanks. :) (Actually, I was hoping the OP himself might give an introduction to whoever The Great Mister Lacplac was, but oh well.) May 7 '13 at 4:21

f2[x_, mu2_, sigma2_] := 1/Sqrt[2*sigma2^2]*Exp[-Sqrt*Abs[(x - mu2)/sigma2]]

Integrate[x*f2[x, mu, h], {x, -Infinity, Infinity},
Assumptions -> {Element[mu, Reals], h > 0}]

(*
mu
*)


### Edit

Let's make what he did wrong crystal clear to the OP.

1. Should have used SetDelayed (:=) rather than Set (=) when defining f2.
2. Needed to have an additional assumption that mu was a real number.
• Complex Integral.. Anyway I don't see any reason to use ":=" instead of "=" in this case. "=" works fine. May 7 '13 at 6:14
• @user6932. That's only because you haven't so far made any global assignments to x, mu1 or sigma2. But you have a time bomb ticking away. May 7 '13 at 22:38

One way to circumvent it is like this

f2[x_, mu2_, sigma2_] :=
Piecewise[{{1/Sqrt[2*sigma2^2]*Exp[-Sqrt*((x - mu2)/sigma2)], x - mu2 >= 0},
{1/Sqrt[2*sigma2^2]*Exp[-Sqrt*((mu2 - x)/sigma2)], x - mu2 < 0}}]

Integrate[x*f2[x, mu, sigma], {x, -Infinity, Infinity},  Assumptions -> sigma > 0]

(*
mu
*)