>>>>> "Antonio" == Antonio Lapira <antoniolapira at yahoo.it> writes:
Antonio> ok thanks
Antonio> I have another question
Antonio> if you see this: http://www.youtube.com/watch?v=EypwejBhN34
Antonio> starting from:
Antonio> p:[[1,8.38],[2,9.82],[3,10.33],[4,12.14],[5,13.25]]
Antonio> he gets a lot of functions like:
Antonio> a) y=1.206*x+7.166
Antonio> b) y=0.04571*x^2+0.9317*x+7.486
Antonio> c) y=0.01917*x^3-0.1268*x^2+1.384*x+7.164
Antonio> d) y=-0.1768*x^4+2.134*x^3-8.864*x^2+.....
Antonio> and others
Antonio> In maxima I know how to obtain a) and something like d)
Antonio> what about for example if I'd like to get get something like b) or c) ?
I guess ratinterpol might want to have cross ref to minpack_lsquares
and lbfgs.
Here's one way got get c) using maxima:
/* Load minpack */
load(minpack)$
p:[[1,8.38],[2,9.82],[3,10.33],[4,12.14],[5,13.25]]$
/* Evaluate cubic a*x^3+b*x^2+c*x+d at each of the points in p */
eq:map(lambda([z], block([x:z[1],y:z[2]], a*x^3+b*x^2+c*x+d-y)), p)$
/* Find the best fit of a,b,c,d to the set of equations */
minpack_lsquares(eq, [a,b,c,d], [0,0,0,0]);
[[.01916666666666679, - .1267857142857145, 1.384047619047617,
7.164000000000004],
.5055817017484493, 3]
/* Map the result of minpack to the form a = value */
map(lambda([v,z],v=z),[a,b,c,d],%[1]);
[a = .01916666666666679, b = - .1267857142857145,
c = 1.384047619047617, d = 7.164000000000004]
/* Plug in the values into the polynomial */
subst(%,a*x^3+b*x^2+c*x+d);
.01916666666666679*x^3-.1267857142857145*x^2+1.384047619047617*x +7.164000000000004
You can also use lbfgs to get this. Ther are probably other ways.
Ray