ev, subst, funmake, quote, apply ... argh!



Hello Daniel,

> Suppose I define a function which computes a figure of merit (rather
> than an expression, this is more of a computational function). An
> example, I want to minimize the max absolute error of my polynomial 
> across a table of x,y values.
>
> xypairs := [[1,1],[2,3],[3,7],[5,4],[8,9]];
>   
Remove the = symbol:

xypairs : [[1,1],[2,3],[3,7],[5,4],[8,9]];

> err(a,b,c,d) := lmin(map(lambda([x,y],float(abs(a+b*x+c*x^2 - y))),
> xypairs)))
>
>   
This gives an error. I think you want

err(a,b,c,d) := lmin(map(lambda([z],float(abs(a+b*z[1]+c*z[1]^2 - 
z[2]))),xypairs));

instead.

> now I want to do something like this...
>
> minimize_sa(err(a,b,c,d) [a,b,c,d],[1,2,3,4]...)
>   
This is what I get when I call the minimize_sa function you posted here 
some days ago:

(%i5) minimize_sa(err(a,b,c,d),[a,b,c,d],[1,2,3,4],[.2,.2,.2,.2],200,1);

... lot of output ending with : ...
.2439296723071309  at  [- 2.64812731589967, 1.152268176851885,
                                         2.251929466740654, 
2.450659004074396]
.06084231875180635  at  [- 2.352474069736563, .9650967722325368,
                                         2.448219616255833, 
2.650011251537803]
(%o5) [a = - 2.976922266760927, b = 1.983462735305637, c = 
2.001567246303038,
                                                          d = 
2.19463014217743]
(%i8) time(%o5);
(%o8)                             [2.184136]

Calling subst instead of ev gives a similar result, but takes a much 
longer time (clisp environment):

(%o10) [a = - 1.287086307145229, b = .7019383009970642, c = 
1.57832084135804,
                                                         d = 
.2015258757874304]
(%i11) time(%o10);
(%o11)                            [72.49253]


hth

-- 
Mario Rodriguez Riotorto
www.biomates.net