Best way to use a compiled function in findroot



On 27/08/2010 20:33, Robert Dodier wrote:
> On Fri, Aug 27, 2010 at 12:24 PM, Sergio Callegari
> <sergio.callegari at gmail.com>  wrote:
>
>    
>> Yes, of course... sorry for all the mistakes in writing in the code... but
>> you got the idea.
>>      
> I'm sorry to say it, but, it's in your own interest to ask a well-formed
> question; it increases your chances of getting a well-formed answer.
>    
You are right... it is only that wxmaxima (at least on linux) is not 
nice at all at cut and paste.
>> Any idea at the correct way to code 'g' ?
>>      
> Works for me as it stands.
> g(0);
>   =>  0.0
>    
This is what I get with latest maxima... now properly copied:

(%i1) f(x):=(mode_declare(x,float),sin(x));
(%o1)              f(x) := (mode_declare(x, float), sin(x))
(%i2) compile(f);
(%o2)                                 [f]
(%i3) g(y):=block([x:gensym()],findroot(f(x)-y,x,-1,1));
(%o3)    g(y) := block([x : gensym()], findroot(f(x) - y, x, - 1, 1))
(%i4) g(0);
Maxima encountered a Lisp error:

  The value $G899 is not of type DOUBLE-FLOAT.

Automatically continuing.
To enable the Lisp debugger set *debugger-hook* to nil.
(%i5) g(y):=block([x:gensym()],findroot('f(x)-y,x,-1,1));
(%o5)    g(y) := block([x : gensym()], findroot('f(x) - y, x, - 1, 1))
(%i6) g(0);
(%o6)                   findroot(f(g900), g900, - 1, 1)
(%i7) g(y):=block([x:gensym()],findroot('(f(x)-y),x,-1,1));
(%o7)   g(y) := block([x : gensym()], findroot('(f(x) - y), x, - 1, 1))
(%i8) g(0);
(%o8)                  findroot(f(x) - y, g901, - 1, 1)
(%i9)

So in my case it does not seem to work, neither with quoting nor without.

Best,

Sergio