I already know that there are built-in functions to compute the Fourier coefficients but I want to derive their formulas manually. In fact, I want to obtain the final well-known formulas for the coefficients with Mathematica carrying a step by step approach. Like the way we do on paper by hand.
So I consider an arbitrary function $f(x)$. I want to start with the known equation
$$f(x)=a_0+\sum _{i=1}^n \left[a_i \cos \frac{i\,\pi}{L} x +b_i \sin \frac{i\, \pi}{L} x \right] \tag{1}$$
and then use the orthogonality relations of trigonometric functions over $[-L,L]$ to derive $a_i$ and $b_i$. Specifically, the steps are
- Multiplying by $\cos \frac{j\,\pi}{L} x$ and $\sin \frac{j\,\pi}{L} x$.
- Integrating over $[-L,L]$.
- Using orthogonality relations.
- Finding coefficients.
As I am new to Mathematica I do not know that what is the best way to proceed.
This is my little effort. But I don't know how to simplify further. I need to distribute the integration over summations and get any constant out of the integrals. Then I should use orthogonality and finally I should find the coefficients $a_i$.
Any hint or help is appreciated. :)
Eq = f[x] == Subscript[a, 0] + Sum[Subscript[a, i]*Cos[((i*Pi)/L)*x] +
Subscript[b, i]*Sin[((i*Pi)/L)*x], {i, 1, n}]
For[i = 1, i <= 2, i++,
Eq[[i]] = Inactive[Integrate][Cos[(j \[Pi])/L x] Eq[[i]], {x, -L, L}];
]