robert.dodier at gmail.com
Sat Jan 13 12:34:27 CST 2007
On 1/13/07, Andrei Dubovik <andu at inbox.ru> wrote:
> g(a) := find_root(f(x,a),x,xmin,xmax);
> g(0.5); --> should give the appropriate numerical solution (this works with
> the above definition)
> g(z+z); --> should give g(2z),
> at(%,z=0.25); --> should give the number immidiately
> plot2d(g(z),[z,zmin,zmax]); --> should work
Well, if all you want is for the plot to succeed, you can write:
plot2d (g, [z, <whatever>, <whatever>]);
which postpones the evaluation of g until it has a numeric argument.
g(z) is evaluated before plot2d is called, so plot2d cannot even get
started (because g(z) with symbolic argument fails).
> Somehow there seems to be nothing in the documentation on it (I tried
> everything I could imagine with ' and '' and was trying to make a wrapper
> that returns just a symbol when the argument is not a number, but I didn't
> succeed to make everything work.) I.e. I'd like to have a function just like
> an ordinary one, say, sin(x).
OK, I guess what you want is for find_root(<foo>, x, xmin, xmax)
to return the unevaluated expression find_root(<foo>, x, xmin, xmax)
when <foo> is not a function of x alone (or something like that).
Unfortunately find_root is a strictly numerical function; if <foo>
evaluates to something other than a number, it barfs.
(Although find_root could be modified to return the unevaluated
So you'll have to handle the different cases in your wrapper function.
g(a) := if numberp(a) then find_root(f(x,a),x,xmin,xmax) else funmake(g, [a]);
(f(x, a) := x^a - 2, xmin : 0, xmax : 10); /* e.g. */
g(0.5); => 4.0
g(z + z); => g(2*z)
at(%, z=0.25); => g(0.5)
''%; => 4.0
plot2d (g(z), [z, 0.5, 2]); => makes a plot
plot2d (g, [z, 0.5, 2]); => makes a plot
A note for everyone else -- find_root evaluates its arguments in a
nonstandard way, and that has caused problems in the recent past,
but I don't think that's a factor here.
Hope this helps
More information about the Maxima