Lagrange Interpolation With Expand Returning a Wrong Result in Maxima

260 Views Asked by At

Recently I've been experimenting with polynomial interpolation to create a simple model of a battery discharge curve. My mathematics knowledge is a bit limited and this is part of my quest to find interesting things that my professors never mentioned.

I've found something very interesting while playing around with Maxima, if I use 10 points in the lagrange function I get the right result, but when I use the expand function I get the wrong result.

(%i1) load(interpol)$

(%i2) p:[[0.000000,9.429000],[10.000000,8.911000],[20.000000,8.707000],[30.000000,8.581000],[40.000000,8.502000],[50.000000,8.430000],[60.000000,8.356000],[70.000000,8.287000],[80.000000,8.228000],[90.000000,8.185000],[100.000000,8.144000],[110.000000,8.100000],[120.000000,8.038000],[130.000000,7.990000],[140.000000,7.960000],[150.000000,7.934000],[160.000000,7.905000],[170.000000,7.877000],[180.000000,7.844000],[190.000000,7.785000],[200.000000,7.728000],[210.000000,7.686000],[220.000000,7.653000],[230.000000,7.613000],[240.000000,7.580000],[250.000000,7.549000],[260.000000,7.524000],[270.000000,7.498000],[280.000000,7.469000],[290.000000,7.438000],[300.000000,7.381000],[310.000000,7.336000],[320.000000,7.279000],[330.000000,7.190000],[340.000000,7.113000],[350.000000,7.034000],[360.000000,6.906000],[370.000000,6.763000],[380.000000,0.011100]];
(%o2) [[0.0, 9.429], [10.0, 8.911], [20.0, 8.707], [30.0, 8.581], 
[40.0, 8.502], [50.0, 8.43], [60.0, 8.356], [70.0, 8.287], [80.0, 8.228], 
[90.0, 8.185], [100.0, 8.144], [110.0, 8.1], [120.0, 8.038], [130.0, 7.99], 
[140.0, 7.96], [150.0, 7.934], [160.0, 7.905], [170.0, 7.877], [180.0, 7.844], 
[190.0, 7.785], [200.0, 7.728], [210.0, 7.686], [220.0, 7.653], 
[230.0, 7.613], [240.0, 7.58], [250.0, 7.549], [260.0, 7.524], [270.0, 7.498], 
[280.0, 7.469], [290.0, 7.438], [300.0, 7.381], [310.0, 7.336], 
[320.0, 7.279], [330.0, 7.19], [340.0, 7.113], [350.0, 7.034], [360.0, 6.906], 
[370.0, 6.763], [380.0, 0.0111]]
(%i3) l:lagrange(p);
<< Expression too long to display! >>
(%i4) fl(x) := ev(l);
(%o4)                           fl(x) := ev(l)
(%i5) fl(110);
(%o5)                                 8.1
(%i6) e:expand(l);
<< Expression too long to display! >>
(%i7) fe(x) := ev(e);
(%o7)                           fe(x) := ev(e)
(%i8) fe(110);
(%o8)                          134287.8427835584

Why do I get this massive difference when I use the expand function? Is there a way to fix this?

1

There are 1 best solutions below

0
On

Interpolating $n$ equally spaced points with an $n-1$ degree polynomial will almost always result in a polynomial with HUGE oscillations$^*$. You would do better to use a low degree spline or to try to find the nature of the data you are trying to model and use that imformation to find a more appropriate function than a polynomial.

$^*$ Try plotting $x(x-1), x(x-1)(x-2), x(x-1)(x-2)(x-3), \dots$and see what kind of plots you get.