Subject: Best way to use a compiled function in findroot
From: Sergio Callegari
Date: Fri, 27 Aug 2010 20:11:43 +0200
Hi,
suppose I make a compiled function
f(x):=(mode_declare(x,float),sin(x));
compile(x);
[obviously here the function is quite naive, but this is just for
example sake]
let us suppose that I want to use find_root on it (just suppose it is a
more complicated function)
find_root(f(x),x,-1,1);
does not work... find root tries to evaluate its first argument and I get
Maxima encountered a Lisp error: The value $X is not of type
DOUBLE-FLOAT.Automatically continuing.To enable the Lisp debugger set
*debugger-hook* to nil.
fine, so let me try
find_root('f(x),x,-1,1);
this works! So far so good.
Let me now try to use it to define an inverse function
g(y):=block([x:gensym()],findroot('f(x)-y,x,-1,1));
no... this does not work...
g(0);
gives:
findroot(f(g2097),g2097,-1,1)
however, also
g(y):=block([x:gensym()],findroot(f(x)-y,x,-1,1));
does not work.
So what is the correct approach?
Thanks in advance,
Sergio