interpolation



On 11/30/2012 02:39 PM, Antonio Lapira wrote:

> if you see this: http://www.youtube.com/watch?v=EypwejBhN34
> starting from:
> p:[[1,8.38],[2,9.82],[3,10.33],[4,12.14],[5,13.25]]
>
> he gets a lot of functions like:
> a) 	y=1.206*x+7.166
> b) 	y=0.04571*x^2+0.9317*x+7.486
> c)	y=0.01917*x^3-0.1268*x^2+1.384*x+7.164
> d)	y=-0.1768*x^4+2.134*x^3-8.864*x^2+.....

use the right tool for the job---this kind of fitting is numerical and 
that's why he's using Matlab. The Free equivalent would be Octave, and 
you can do polynomial fits all day long there:

x=1:5;y=[8.3800    9.8200   10.3300   12.1400   13.2500];

plot(x,y,'o',x,polyval(polyfit(x,y,1),x))
plot(x,y,'o',x,polyval(polyfit(x,y,3),x))

etc. The coefficients are given by the fit function:

polyfit(x,y,3)
ans =

    0.019167  -0.126786   1.384048   7.164000

Of course, you have a point that Maxima can do this stuff too, but 
perhaps within Octave it's easier to understand what calculation is 
being done: it's simply a polynomial least squares minimization; you can 
'type polyfit' or read the man page at 
http://www.mathworks.com/help/matlab/ref/polyfit.html to see the 
algorithm is a least-squares solution of a Vandermonde matrix equation: 
y_j = V_ij * p_i,  where V_ij = x(i)^j, done using the QR factorization.

In other words, there's nothing different about a) b) c) d): just 
different polynomial degrees.