Fourier Series
Overview
The Fourier series can be used to approximate other functions. Under a broad set of conditions, the series converges to the
target function, so one could approximate a function by taking the first {% n %} terms of the Fourier series.
The following demonstrates approximating the function {% f(x) = x^2 %} using the first {% n %} Fourier terms.
Moving the slider changes the number of terms taken. (from 0 to 10)
copy
Implementation
As an example, once one has computed the first 3 cosine
coefficients, once could write a function that approximates
the target function as follows.
let approx = x => {
return 0.5 * a0 + a1 * Math.cos(x) + a2 * Math.cos(2*x);
}
Then, we can chart the results by creating a set of
samples as in the following.
let samples = $from(-1 * Math.PI, Math.PI, 1000).map(p=>{
return {
x:p,
y:approx(p)
};
})
Try it!