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~~ nin Integers,~nge 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 (Element) 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 (Element) Integers && n > 0 && x (Element) 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.