[Maxima] plotting numeric functions
limboj01 at student.uwa.edu.au
Mon May 24 03:37:03 CDT 2010
On Mon, 24 May 2010 15:28:23 +0800, Leo Butler <l.butler at ed.ac.uk> wrote:
> On Mon, 24 May 2010, James Limbouris wrote:
> < Hi all,
> < Something I have had trouble with for quite some time is the plotting of
> < numeric functions.
> < Say you have a very complicated function f(x), that will go away and not come
> < back if you attempt
> < to evaluate it symbolically. Maybe its definition contains a bunch of nested
> < noun form functions
> < for instance. Now say it evaluates instantly as:
> < f(x), x=3, numer, keepfloat;
> < But if you try to plot it:
> < wxplot2d(f(x), [x, 1, 3]), numer;
> < it will go away and not come back. Now if it were just a numeric function that
> < required that its
> < arguments be floats, you could fix this by using:
> < wxplot2d('f(x), [x, 1, 3]), numer;
> < The quote would suppress evaluation of f(x) until its arguments were
> < substituted, and it would work.
> < But for hideous analytic functions, I have had no luck with any combination of
> < quotes, or hacks of the form:
> < hack(expression, x) :=
> < block(
> < if not numberp(x) then return('hack(expression, x)),
> < return(ev(expression, expand, nouns, numer, keepfloat))
> < )$
> < or anything else I can think of.
> < I know you can do discrete plots in 2D, but plot3D has no discretes, and
> < draw3d's mesh function gives incorrect axis values.
> < Does anyone know a way around this? Can any developers see a why to fix this
> < behavior? Any help advice would be much appreciated.
> < Thanks,
> < James
> Hi James,
> It's difficult to know what your problem really is unless you provide us
> with an example. Do you have an example that you could send us?
> It is intrinsically a worthwhile exercise in coming up with a 'simplest'
> example, too. This often clarifies what the real problem is.
Here is a example from the problem I'm currently working on. I apologize for the length
of the function, but it is difficult to imagine a simple one that will fail to evaluate.
f(nr, ni) :=
< snip >
For the gory details see the attached .wxm file. Essentially, it is a nasty long mixture of polynomials, rationals and exponentials.
I do not suspect it of being too numerically ill-conditioned to evaluate, and either of the following:
f(nr, ni), nr=2, ni=1, numer, keepfloat;
will return a complex number instantly. Now lets try to get the modulus of this complex number:
abs(f(2, 1)), numer;
abs(f(nr, ni)), nr=2, ni=1, numer;
all return instantly, while abs(f(nr, ni)) crashes with an out of memory error, after several minutes.
Now the problem is,
wxplot3d(f(nr, ni), [nr, 1, 2], [ni, 1, 2])
will produce a plot, but
wxplot3d(abs(f(nr, ni)), [nr, 1, 2], [ni, 1, 2]), numer;
wxplot3d('abs(f(nr, ni)), [nr, 1, 2], [ni, 1, 2]), numer;
will not. So evaluating abs(f) at the prompt works instantly, but evaluating it in the plotting function does not.
In the past I have gotten around this by using makelist to prepare the values, and then doing a discrete plot.
However, this isn't a viable option in 3D, because there is no discrete 3D plot, except for draw3D's mesh. But the
mesh doesn't work quite right, and would be a workaround in any case. I was hoping that there would be some way to
just get it to work the way you'd expect it to.
The attached file shows the gory function, and several attempts to evaluate it.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 6407 bytes
Desc: not available
More information about the Maxima