plotting numeric functions




On Mon, 24 May 2010, Robert Dodier wrote:

< On 5/24/10, Leo Butler <l.butler at ed.ac.uk> wrote:
< 
< > James, after playing around a bit, I think the problem is simply that
< > compiling your function exhausts all heap space (1G in my case). I don't
< > know if this is a bug in Maxima's compiler (probably),
< 
< I kind of wonder what you mean by this, since the translator and
< compiler are not invoked by plotting. I'm pretty sure the problem
< is that abs(f(x, y)) fails when x and y are symbols since abs then
< attempts to construct an expression which is either too big or
< takes too long to construct.

Translation of f works fine, but compilation exhausts the heap space,
too. I was under the (mistaken) impression that coerce-float-fun does
a compilation step, but this is mistaken.

< 
< Here's another attempt to forestall evaluation of abs(f(x, y)) until
< x and y are numbers. I think this one works.
< 
< matchdeclare ([xx, yy], numberp);
< tellsimp (g (xx, yy), f (xx, yy));
< plot3d (abs (g (nr, ni)), [nr, 1, 2], [ni, 1, 2]);
< 
< This makes g a simplifying function; for anything other than
< numerical argument, it doesn't simplify. For numerical arguments
< g(x, y) simplifies to f(x, y).

Yes, this solution works. Here is another solution like that you
proposed earlier which avoids writing simplification rules:

kill(F);
ns_abs(f,x,y):=if numberp(x) and numberp(y) then abs(f(x,y)) else nounify(abs)(nounify(F)(x,y));
plot3d (lambda([nr,ni], ns_abs (f , nr, ni)), [nr, 1, 2], [ni, 1, 2]);


< 
< Now it is certainly unfortunate that any workaround is needed
< to get the example to work. The main problem is that computing
< abs is a pretty difficult problem. I don't know what we could do to
< avoid running out of time or memory.
 
You are right in that any attempt to simplify the expression f(x,y)
is going to cause problems. However, plot3d attempts to evaluate
the expression as a 'safety' measure -- it doesn't trust the user hasn't
mistakenly added extra symbolic variables. We could simply add a
'trust_me_I_know_what_I_am_doing' plot option that cuts out that
step. On the other hand, maybe we should just patch the documentation
and add a note on how to plot functions like this one.

Leo

-- 
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.