# How to find the Maximal Absolute Error?

I found this fit but I do not understand how to find the maximal absolute error nor do I understand what it is really. I do not see what it is I would compare, would it be f[-2] to lets say p4?

f[x_] = 1/(1 + x^2);
f[-2];
f[-1];
f;
f;
f;
XY = {{-2, 1/5}, {-1, 1/2}, {0, 1}, {1, 1/2}, {2, 1/5}};
p4[x_] = Fit[XY, {1, x, x^2, x^3, x^4, x^5}, x];


f[x_] := 1/(1 + x^2)
fitf[x_] = Fit[{#, f[#]} & /@ Range[-2, 2], x^Range[0, 5], x] // Chop


1.-0.6 x^2 + 0.1 x^4

The absolute error is just the (sometimes) absolute value of the difference between the measured value and the predicted value.

Plot[{f[x], fitf[x], Abs[f[x] - fitf[x]]}, {x, -2, 2}] Then we can find the maximum of the absolute error and its location with

NMaximize[{Abs[f[x] - fitf[x]], -2. <= x <= 2.}, x]


{0.161803, {x -> -1.61803}}

• The equation makes sense now, thanks! But I am now confused what you did for the fit function? if we have 5 points wouldn't that mean we would have a degree 4 polynomial? – Sherien Hassan Oct 22 '19 at 21:38
• Oh, no I think my code was incorrect because I had it go up to x^5 when it was supposed to stop at x^4. Thanks again!! – Sherien Hassan Oct 22 '19 at 21:45
• @SherienHassan The output of Fit[{#, f[#]} & /@ Range[-2, 2], x^Range[0, 5], x] is 1. - 1.10913*10^-15 x - 0.6 x^2 - 5.23354*10^-16 x^3 + 0.1 x^4 - 8.90048*10^-17 x^5. Chop replaces the coefficients less than 10^-10, which are effectively 0, with 0. Thus the odd powers drop out. – That Gravity Guy Oct 22 '19 at 21:48
• Hmm I am still sort of confused, I understand how the chop function works but I thought needed n-1 degree. So given 5 points we would have a degree 4 polynomial? I might be understanding interpolation incorrectly. – Sherien Hassan Oct 22 '19 at 21:56
• @SherienHassan, function f[x] is symmetric, so there should not be odd powers in fitting polynomial. – Alx Oct 23 '19 at 3:43