[Math] Lagrange interpolation not working

interpolationlagrange-interpolation

I have been trying to use Lagrange Interpolation on some data to find the equation of a curve that fits the following points (x,y):

(0,5.2) (1,3.8) (2,4.5) (3,5.5) (4,6) (5,6.25) (6,6.25) (7,6) (8,5.6) (9,5) (10,4.2) (11,3.5) (12,2.6)

And I've been using this website: http://www.dcode.fr/lagrange-interpolating-polynomial

It gave me a result, but when i copied and pasted this equation into desmos (to graph it), the curve only went through my first 4 points, then the curve just fell away and didn't fit my data from then on. I've check and re-checked my work, but can't seem to figure out what's going wrong. If anyone could work out what I'm doing wrong, that would be tremendously appreciated.

I guess you can try it out for yourself, copy and paste the points from my orginial post into the online calculator (link given in original post) and then graph the resulting function. I also did a search into wolfram alpha: "interpolate polynomial {0,5.2},{1,3.8},{2,4.5},{3,5.5},{4,6},{5,6.25},{6,6.25},{7,6},{8,5.6},{9,5},{10,‌​4.2},{11,3.5},{12,2.6}" which gave me the same equation. (You can check this out for yourself too if you wish to).

Is there any other way of finding an equation that roughly fits my data??

Best Answer

Is there a reason that you believe your data is well-modeled by a 12th degree polynomial? Is this an exercise in using Lagrange interpolation, or an actual attempt to fit real data? Possible reasons for failure are (1) bad coding at that website, (2) bad data entry, or (3) numerical problems. by the time you take the 12th power of a number like 11, you may get overflows, depending on the representation of numbers in your graphing software.

Here's the answer: it wasn't overflow, it was rounding error. The answer from your web-query was this: $$ f(x) = -\text{1.2526054192711...$\times 10^{-9}$} x^{12}+\text{2.0542728876055...$\times 10^{-7}$} x^{11}-0.0000109816 x^{10}+0.000301615 x^9-0.00497731 x^8+0.0528069 x^7-0.369466 x^6+1.69712 x^5-4.92847 x^4+8.19225 x^3-5.79708 x^2-0.242482 x+5.2 $$

Do you see those "..." in there? That's stuff that got eliminated from the result because it required too many decimal digits. Now look at what happens when you plug in $x = 10$: you get $$ f(10) = -\text{1.2526054192711...$\times 10^{-9}$} \times 10^{12}+\text{2.0542728876055...$\times 10^{-7}$} \times 10^{11}-0.0000109816 \times 10^{10}+0.000301615 \times10^9-0.00497731 \times10^8+0.0528069 \times 10^7-0.369466 \times 10^6+1.69712 \times 10^5-4.92847 times 10^4+8.19225 times 10^3-5.79708 \times 10^2-0.242482\times 10+5.2. $$ If you work out the first few terms of that, you get $$ f(10) \approx -1252.605... + 20542.7288 + 30161500 $$ and the question becomes "is that ".301615" exact, or is it, too, a finite decimal approximation of the right answer? Because if it's the latter, then when you multiply by $10^{10}$, the last two digits could be almost anything instead of "00"; such an error would make your interpolation miss by upp to a distance of 100. Yikes!

Related Question