I am using Mathematica to develop some ``interesting" problems for students to solve using Fourier series.
The following computation seems as though it should yield a real result:
$B_n = \int_0^1 \exp(-9 x^2) \cos(n \pi x)\, dx~~ n\in Integers,~n\ge 0$
When I code this in Mathematica, I find it returns a complex result, which does not seem plausible. Here is the code for the first term $(n=0)$ (which is simpler than the general case):
B[0] = Integrate[Exp[-9x^2], {x, 0, 1}, Assumptions -> {x ∈ Reals}] This returns $\tfrac{1}{6}\sqrt{\pi} \,\textrm{erf}{(3)}$, which is the correct answer.
However, when I compute the integral for the values of $n>0$, I find the following:
B[n_] = 2 Integrate[Exp[-9x^2] Cos[n Pi x], {x, 0, 1}, Assumptions -> {n ∈ Integers && n > 0 && x ∈ Reals}] Returns: $\frac{1}{6} \sqrt{\pi } e^{-\frac{1}{36} \pi ^2 n^2} \left[\text{erf}\left(3-\frac{i \pi n}{6}\right)+\text{erf}\left(3+\frac{i \pi n}{6}\right)\right]$
This is a bit baffling. I see no reason that we should have wandered into the complex plane to compute this integral. Anyone have some perspective here?
Thanks.
Conjugate[Erf[Conjugate[z]]] // FullSimplify. (See for example, the Schwarz reflection principle and the "identity theorem".) $\endgroup$1/6 E^(-(1/36) n^2 \[Pi]^2) Sqrt[\[Pi]] (Erf[Conjugate[z]] + Erf[z]) // Im // FullSimplify[#, n > 0 && n \[Element] Integers] &$\endgroup$TrigToExp[Exp[-9x^2] Cos[n Pi x]]puts the integrand in a form that reveals whereErf[]with a complex argument comes from. $\endgroup$