10
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ I'm pretty sure this has been asked before, but I can't find it. Anyone? $\endgroup$ – Dr. belisarius Sep 29 '13 at 21:01
11
$\begingroup$

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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