Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to compute the following integral:

Integrate[Exp[Sum[-((cw λ - b[i])^2/(2 σ^2)), {i, 1, n}]], {cw, 0, 1}]

And currently Mathematica outputs

(Sqrt[π/2] σ (Erf[(Sqrt[n] (λ - b[i]))/(Sqrt[2] σ)] + 
     Erf[(Sqrt[n] b[i])/(Sqrt[2] σ)]))/(Sqrt[n] λ)

Which is not only blatantly incorrect (there can be no dependence on i for example), but also has little connection with my input. If I replace n with an integer in the first expression, the output is the correct result for the integration, but I want the general result with n summands. What am I doing wrong?

Edit: I am willing to make assumptions, such as that λ, σ and all b[i]'s are real. Nonetheless, that does not seem to matter here.

share|improve this question
I'm pretty sure this has been asked before, but I can't find it. Anyone? – Dr. belisarius Sep 29 '13 at 21:01
up vote 11 down vote accepted

In this particular case Mathematica for some reason considers b[i] as a constant. Compare:

Integrate[Exp[Sum[-((cw λ - b)^2/(2 σ^2)), {i, 1, n}]], {cw, 0, 1}]
(Sqrt[π/2] σ (Erf[(b Sqrt[n])/(Sqrt[2] σ)]-Erf[(Sqrt[n] (b-λ))/(Sqrt[2] σ)]))/(Sqrt[n] λ)

A possible workaround consists in the manually expanding the sum

Integrate[Exp[(-n cw^2 λ^2 + 2 cw λ Sum[b[i], {i, 1, n}] - 
  Sum[b[i]^2, {i, 1, n}])/(2 σ^2)], {cw, 0, 1}]

enter image description here

There is another example of the strange behavior of the sum of b[i]

Sum[cw b[i], {i, 1, n}] - cw Sum[b[i], {i, 1, n}]

enter image description here

It is not simplified to 0 (even with Simplify and FullSimplify).

share|improve this answer
I have expanded the sum already, but this is quite a quirk... – em70 Sep 29 '13 at 22:30
Would you not consider this a bug ? – b.gatessucks Sep 30 '13 at 7:12
@b.gatessucks Yes, it looks like a bug. I usually look for my own mistakes before considering something as a bug. – ybeltukov Oct 2 '13 at 14:39

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.