0
$\begingroup$

I'm running Mathematica 7.0.0 and came across this weird calculation (lines 1-14).

f[x_, r_] := x*(r - x)*Exp[-Pi*I/(2 r)*x^2]; g[x_, r_] := Exp[-Pi*I/(2 r)*x^2]*(r - Pi*I*x^2 - 2*x + Pi*I/r*x^3); int[r_] :=    FullSimplify[    Integrate[f[x, r], {x, 0, r}] +      Integrate[-Sum[Sin[2*Pi*n*x]/(n*Pi), {n, 1, Infinity}]*       g[x, r], {x, 0, r}], r > 0 && Element[r, Integers]]; int[r] // N int[12] // N  Output: 0. 2.64102 - 39.4256 I 

So I've got two functions, $f$ and $g = f'$, and I'm interested in a certain expression (as shown). However, the general expression that Mathematica 7 gives for positive integers $r$ is $0$, whereas it gives something non-zero for particular integers $r$ (as it should).

Can somebody with Mathematica 8 verify this or tell me why I shouldn't be surprised? Thanks.

  • 0
    Well, I get the same results with 8.0.1.0 on a Mac.2011-11-17
  • 1
    @Sasha: I'm not quite sure what you mean; the expression is a sum of two integrals, neither of which are constant in $r$.2011-11-17
  • 0
    @SørenFugledeJørgensen Yes, you are right, of course. The value of the integral depends on `r`, my bad. As castal said, v 8.0.1, but also v 8.0.4 produce the same result as v7.2011-11-17
  • 0
    Thanks to both of you; I'll report it.2011-11-17
  • 0
    Some quick notes. Symbolically integrating both pieces, I get `(-i r^2 + r^(3/2) (i FresnelC[Sqrt[r]] + FresnelS[Sqrt[2]]))/Pi` for $\int f$ and its negative for the second integral. However, integrating them both with a definite value of $r$, I get different results. For $r=5$, the sum is $1.19-5.00i$, and for $r=6$, the sum is $3.30-9.00i$, rounded, of course. I wonder if this is similar to the problem of integrating $\cos(q x)$ with $q \in \mathbb{Z}$.2011-11-17
  • 0
    @rcollyer: The first integral being the sum of Fresnel's is fairly immediate, and it gives the correct values for definite $r$, but it's a mystery to me how the second one ends up as the exact negative as the first one. I guess I'll try to do that one by hand when I get the chance.2011-11-17
  • 0
    I have no idea why it ends being the exact negative. A guess is that like $\int^\pi_{-\pi} \cos(qx)$ with $q\in\mathbb{Z}$, there are multiple solutions depending on $r$, and by not fixing its value, Mathematica blithely chooses the incorrect one.2011-11-17
  • 0
    @rcollyer: I'm not quite following you; what's the parameter in $\int_{-\pi}^\pi \cos(qx)$ that the solution depends on (you wrote $r$ but that's probably a typo?)?2011-11-17
  • 0
    Sorry, mixing messages there. $\int^\pi_{-\pi} \cos(qx) = 2$ when $q = 0$, but $0$ otherwise. But, you get the wrong answer if you integrate first and then set $q=0$. So, I was wondering if we're running into something similar with regards to $r$ in your integrals, but I didn't write it out as fully as I should have.2011-11-17
  • 0
    @rcollyer: That sounds likely; in this case Mathematica would give two results for the last integral, depending on the sign of $r$. In fact, if one changes every single $r$ to $r-1$, theoretically the value of the sum would change only by $f(r-1)/2$, but Mathematica gives a result which is not well-defined for integral values of $r$ (more precisely, it gives something like $\mathrm{Log}(1 - exp(2\pi i r))$.2011-11-17
  • 1
    Also, `Integrate` doesn't do anything with an integer assumption ([see the comments](http://stackoverflow.com/q/7743774)), so you have to watch out for them yourself.2011-11-17

1 Answers 1