I don't know if this is the appropriate place to ask this, but I really do need some help. I am doing a homework problem and I don't understand what is being asked. It goes as follows:
Write a MATLAB function to evaluate the trigonometric interpolant $p_n(x)$ for a given set of samples, $\bf{y}$:
Here it follows with some comments about making such a function, I'll leave that out since it's not relevant, but it goes on to say:
To test your program use $f(x) = 10cos(x)+5cos(3x)$ and plot the maximum error $max |p_n(x)-f(x)|$ for $n= 4,8,16,32,64.$ Verify that the maximum error is close to machine precision for $n=32,64.$ What is the reason behind this?
So I was able to find the interpolating function $p_n(x)$, but I don't know what the next part is asking. Am I supposed to find the maximum value of $g_n(x) = |p_n(x)-f(x)|$ for each $n$, say it is $g_n(x_0)$, then plot $g_i(x_0)$ vs $i$ for $i= 1...n$? So effectively, each value $g_i(x_0)$ is plotted on an $y$- axis and $i$ on a corresponding $x$-axis? Or am I simply supposed to make a plot of $g_n(x) = |p_n(x)-f(x)|$ for each n?
Also, how do I know when I am close to machine precision? When I start getting cancellation errors?
Thank in advance for the help.
By the way, I am using Julia to do this, not MATLAB.
You are to interpolate $f$ by $$ p_{n=2m}(x)=a_0+\sum_{j=1}^{m-1}(a_j\cos(jx)+b_j\sin(jx))+a_{m}\cos(mx) $$ at samples $y_k=f(x_k)$, $x_k=k\frac{2\pi}n=k\frac{\pi}m$.
Regardless of how you solve the resulting linear system for the coefficients, for $$f(x)=10\cos(x)+5\cos(3x)$$ the solution is uniquely given by $a_1=10$, $a_3=5$, all other coefficients $0$ for $m\ge 3$, $n\ge 6$. All deviations from that result are due to floating point noise, and since the discrete Fourier transform is orthogonal, the relative size of the noise is bounded to essentially the machine constant. For the given sample sizes this should happen for $n=8,16,32,64$.
For the original task description from in [1], where $$ f(x)=10\cos(x)-3\sin(3x)+5\cos(3x)-15\cos(10x) $$ interpolation results in exact reconstruction of that formula for $m\ge 10$, $n\ge20$, so that indeed only in the cases $n=32,64$ one can expect the errors to be on the magnitude of $10\epsilon$.