We want to write a function as a sum of sines and cosines. The
orthogonality
of those building blocks hands us each coefficient almost for free — by exactly the same
projection that recovers a vector's components.
For a vector, the component along a unit axis \mathbf{e}_k is the
dot product \mathbf{v}\cdot\mathbf{e}_k. For a function we project the
same way: to find the amount of \sin\frac{n\pi x}{L} inside
f, take the inner product of f with that
mode and divide by the mode's own "length squared".
Deriving one coefficient
Suppose f(x) = \sum_k b_k \sin\frac{k\pi x}{L}. Take the inner product
of both sides with a single mode \sin\frac{n\pi x}{L}:
\int_{-L}^{L} f(x)\sin\frac{n\pi x}{L}\,dx = \sum_k b_k \int_{-L}^{L}\sin\frac{k\pi x}{L}\sin\frac{n\pi x}{L}\,dx.
Orthogonality kills every term in the sum except k = n, where
the integral equals L. The entire infinite sum collapses to one term:
\int_{-L}^{L} f(x)\sin\frac{n\pi x}{L}\,dx = b_n\,L \;\Longrightarrow\; b_n = \frac{1}{L}\int_{-L}^{L} f(x)\sin\frac{n\pi x}{L}\,dx.
That is the whole idea: orthogonality turns "solve for infinitely many unknowns at once" into
"read off each one with a single integral".
For a function f on [-L, L], the coefficients are
- a_0 = \dfrac{1}{L}\displaystyle\int_{-L}^{L} f(x)\,dx — twice the average value of f.
- a_n = \dfrac{1}{L}\displaystyle\int_{-L}^{L} f(x)\cos\dfrac{n\pi x}{L}\,dx.
- b_n = \dfrac{1}{L}\displaystyle\int_{-L}^{L} f(x)\sin\dfrac{n\pi x}{L}\,dx.
Each b_n is the projection of f onto the nth sine — how much of that ripple is "inside" f.