find_root and variable capture?



I suspect this is the usual quoting issue that has been explained many
times on this list.  I am not sure why it is hard to understand the
problem -- perhaps because Maxima tolerates shortcuts like
find_root(sin(x),x,-1,1) in many cases....

If you don't quote the arguments, they will be evaluated when you
*call* find_root, not when find_root calls them.  This is intentional,
correct, behavior, so that you can write find_root(%o23,'x,...) and so
you can write programs like my_rootfinder( expr, var ) := ...
find_root( expr, var, ...).

The variable capture problem is different -- it is when you get a
conflict between variable names like expr and var and the variables in
your expressions.

Try
    find_root( '( <my expression> ), '<my variable>, ...)
    quad_qag( '( <my expression> ), '<my variable>,...)
etc.

To avoid problems like this, it is best never to use the shortcut
find_root(sin(x),x,-1,1) etc. but always include the quotation marks:
find_root( '(sin(x)), 'x, -1, 1).

Now I know it will immediately be suggested that quoting be the
default, but that is a bad idea.  It would mean that every function
like this would either have a doublet which evaluates or that you have
to call it using "apply", e.g. apply( 'find_root, [ %o23, 'x, 0, 1] ).

I hope this helps.

           -s