I wanted to compute $$\frac{2}{L}\int_0^L\left(1+2\cos\frac{3 \pi x}{L}\right)\cos\frac{n \pi x}{L}\,dx,$$ so my input was
Assuming[Element[n, Integers], Integrate[(2/L)(1 + 2 Cos[3 Pi x/L])Cos[n Pi x/L], {x, 0, L}]].
The answer turns out to be 0 for all $n > 0$ EXCEPT $n = 3$, for which it is $2$. However Mathematica just said the answer is $0$, so I had to know to check that case specifically. How can I type these kinds of expressions in the future to catch one-off cases like this? I know Mathematica cannot just check every $n$ and is using symbolic manipulation to simplify the expression, but even when I bound $n$ in a very tight interval like $[2, 4]$ it said 0.
FourierCosCoefficient
$\endgroup$FourierCosCoefficient
computes the integral between 0 and Pi . If you want to compute it over a different interval you need to specify it withFourierParameters
. $\endgroup$