0
$\begingroup$

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.

$\endgroup$
4
  • 1
    $\begingroup$ Maybe there is a specific reason you want to compute the integral directly but you might be interested inFourierCosCoefficient $\endgroup$ Commented Nov 30, 2022 at 1:35
  • $\begingroup$ @userrandrand I was not familiar, thank you! However, unless I'm using it wrong, now I am not getting anything close to the answer I am looking for. Maybe a subject for another question.... $\endgroup$ Commented Nov 30, 2022 at 1:43
  • 1
    $\begingroup$ Possible duplicate of this. $\endgroup$
    – user293787
    Commented Nov 30, 2022 at 1:50
  • $\begingroup$ @EphraimRuttenberg mathematica has lots of issues one can run into. In those cases it is important to carefully check the documentation, In particular the Details section and possible issues sections are important when confronted with difficulties, The details section explains that by default FourierCosCoefficient computes the integral between 0 and Pi . If you want to compute it over a different interval you need to specify it with FourierParameters. $\endgroup$ Commented Nov 30, 2022 at 2:04

0

Browse other questions tagged or ask your own question.