Overview
This example shows calculating a Fourier series expansion for the function {% y = x^2 %}
Fourier Series Expansion
{% a_0 = 2 \pi ^2 / 3 %}
{% a_n = 4(-1)^n/n^2 %}
Approximation Function
The Fourier series can be used to approximate other functions. 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)
};
})
The following is an example of approximating a parabola {% y = x^2 %} using the first 3 Fourier cosine.
copy