# [Maxima] plotting numeric functions

James Limbouris 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.
>
> Leo
>

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) :=
%i*((((%e^(-12.56637061435917*ni)*(-0.23518915858261*(nr^6-15*ni^2*nr^4+15*ni^4*nr^2-ni^6)-0.86386844040539*(6*ni*nr^5-20*ni^3*nr^3+6*ni^5*nr)-2.217486114751758*
< snip >
1.841137478185708*(4*ni*nr^3-4*ni^3*nr)+64.83122366729704*(nr^3-3*ni^2*nr)+1.615197025742226*(3*ni*nr^2-ni^3)+72.8605673885606*(nr^2-ni^2)+13.8755315023416*ni*nr+
42.81053745639266*nr+6.616193944347959*ni+10.26849837929581)^(2))^(2))

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(2, 1);
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))
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;

or

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.

James
-------------- next part --------------
A non-text attachment was scrubbed...
Name: example.zip
Type: application/zip
Size: 6407 bytes
Desc: not available
URL: <http://www.math.utexas.edu/pipermail/maxima/attachments/20100524/c50d323d/attachment-0001.zip>
```