What is going wrong with this Fourier Series for integer powers of $x$?

98 Views Asked by At

EDIT:

I'm aware I could just add a compensating "$-c_1(0)$" term to get rid of the vertical offset, but that feels not in the spirit of Fourier series... and doesn't explain the mystery anyway.

Into Desmos, I plotted:

$$f(x)=x^k\\c_1(n)=\frac{1}{\pi}\int_{-\pi}^\pi f(x)\cos(nx)\,dx\\c_2(n)=\frac{1}{\pi}\int_{-\pi}^\pi f(x)\sin(nx)\,dx\\\mathcal{F}(x)=\sum_{n=0}^Nc_1(n)\cdot\cos(nx)+c_2(n)\cdot\sin(nx)$$

The $c_1$ and $c_2$ functions are coefficient-finding functions, and rely on Desmos' numerical integration.

And this Fourier series $\mathcal{F}(x)$ fits $f(x)$ very very well, with more accuracy as $N$ increases, only when $k$ is odd. When $k$ is an even integer, the series fits the curve very well still... but at a large y-offset. The series oscillates around some y-intercept, whose value as a function of $\pi$ I have not been able to experimentally determine. For reference, here are two images, the first of $k$ odd, the second of $k$ even. The green lines are the original function, and the red lines are the Fourier series.

$k=3$ and the Fourier series fits well: k=3 $k=4$ and the series fails... bizarre vertical offset. k=4 failure

Many thanks for any suggestions about where this comes from, and how to correct it.

1

There are 1 best solutions below

0
On BEST ANSWER

Answer for any student who may or may not view this later, with credit to @GregMartin: the first coefficient in a Fourier series, when using this method of deriving the coefficients, must be halved: $$c_1(n)=\frac{1}{\pi}\int_{-\pi}^\pi f(x)\cos(nx)\,dx,n\gt0\\c_1(0)=\frac{1}{2\pi}\int_{-\pi}^{\pi}f(x)\,dx$$

This is because in the derivation of the coefficient formulae for cosine, we have $$c_1(n)=\frac{\langle f(x),\cos(nx)\rangle}{\langle\cos(nx),\cos(nx)\rangle}$$

But $$\langle\cos(0\cdot x),\cos(0\cdot x)\rangle=2\pi$$

(but is equal to $\pi$ for all other $n$). The braces denote the inner product calculated over the range $[-\pi,\pi]$.