Not sure if what I'm trying to do makes sense. I am prototyping some code in math, one day I hope to write in C ++. An environment in which I can only calculate with double precision (since I use the MS VC ++ compiler).
I have a polynomial that approximates the function f, and I want to build an error curve. The polynomial coefficients were calculated on the accuracy of the machine (as is the case with C ++). But when I draw a relative error, I just get a graph of numerical noise. I would expect the error to be a smooth curve, since the polynomial is a Taylor polynomial. How can I get a more reasonable plot? The code below demonstrates what I'm trying to do, with the Cos function as a test case. The result of the graph is just numerical noise.
f[x_] = Cos[x] a[k_] := N[(-1)^k/(2*k)!] approx[x_] := Sum[a[k]*x^(2*k), {k, 0, 12}] Plot[approx[x]/f[x] - 1, {x, -Pi, Pi}, WorkingPrecision -> 30]
I could increase the accuracy of calculating the coefficients a[k] .
a[k_] := N[(-1)^k/(2*k)!,30]
to get a more reasonable plot, but that defeats the purpose of my prototype code. Because in the end, I want to graphically display the error graphs that I create in C ++. And in this environment, the coefficients will be calculated only in double precision.
I think this test makes sense? I expect my approximation to be accurate regarding the accuracy of the machine, but how can I plot the error?
Thanks for reading.
source share