Am Donnerstag, den 07.01.2010, 18:45 -0500 schrieb Stavros Macrakis:
> Stanislav, I'm afraid I don't have the time to investigate this case
> in detail, but I do hope I've given you the information you need to
> investigate it yourself.
>
> -s
>
> 2010/1/7 Stanislav Maslovski <stanislav.maslovski at gmail.com>
> On Thu, Jan 07, 2010 at 06:01:03PM -0500, Stavros Macrakis
> wrote:
> > Not surprising. This expression:
> >
> > plot3d(cabs(f(ky,kz)),[ky,-3,3],[kz,-3,3]);
> >
> > means "calculate cabs(f(ky,kz)) as an argument to plot3d
> (without binding ky
> > and kz) -- call the result xxx; now evaluate xxx for various
> numeric values of
> > ky and kz". In other words, it first calculates a *symbolic
> expression* for
> > the absolute value, then evaluates that at various values.
> What you want to do
> > is presumably calculate the *numeric values* of f(ky,kz) at
> various values and
> > then take the cabs of that. You can do that with:
> >
> > plot3d( '( cabs(f(ky,kz)) ),[ky,-3,3],[kz,-3,3]);
> >
> > which should have the same effect as your plot3d(abs_f,...)
> expression.
>
>
> Sure. Then why
>
> plot3d(sqrt(realpart(subst(k0=%i,Ree)^2+imagpart(k0=%
> i,Ree)^2),...)
>
> still works (see the example I sent in my first mail)?
I had a look at the problem. This is the expression which causes the
problem.
(%i3) test;
(%o3) ((sqrt(kz^2+ky^2+1)/(-kz^2-1)-3*sqrt(2*(kz+%i)^2/3+ky^2+3)
/(-(kz+%i)^2-9/2))
*(3*sqrt(2*(kz+%i)^2/3+ky^2+3)/(2*(-(kz+%i)^2-9/2))
+sqrt(kz^2+ky^2+1)/(-kz^2-1))
-(ky*(kz+%i)/(-(kz+%i)^2-9/2)-ky*kz/(-kz^2-1))^2)
/((ky*(kz+%i)/(-(kz+%i)^2-9/2)-ky*kz/(-kz^2-1))^2
+(3*sqrt(2*(kz+%i)^2/3+ky^2+3)/(2*(-(kz+%i)^2-9/2))
+sqrt(kz^2+ky^2+1)/(-kz^2-1))
*(3*sqrt(2*(kz+%i)^2/3+ky^2+3)/(-(kz+%i)^2-9/2)
+sqrt(kz^2+ky^2+1)/(-kz^2-1)))
We try to get the rectform and the absolute value of this expression. It
works well for the rectform, but not for the absolute value. Because the
expression contains the imaginary unit simpabs calls cabs. The result is
a very huge expression. This expression Maxima can not handle. It can
not be displayed, expanded or further simplified.
I think this is a nice example of expression swelling, caused by sqrt
functions with complex arguments (I have seen this problem of expression
swelling when working with nested sqrt functions too and I am wondering
if we can improve this.)
(%i2) rectform(test)$
Evaluation took 0.1000 seconds (0.1860 elapsed) using 223.820 KB.
(%i3) abs(test)$
Evaluation took 19.3220 seconds (19.6480 elapsed) using 153.844 MB.
I searched for the reason, why we have such a huge difference between
rectform and the absolute value. I think the reason is an extra call of
the function $expand in the routine absarg.
(defun absarg (l &optional (absflag nil))
(setq l ($expand l))
...
If we expand the test expression we get a very huge expression as input
to the function absarg. I have removed the call to $expand and had a
look at the new results. Again first the calculation of rectform and the
absolute value. We see that we now get the result for the absolute value
much faster.
(%i5) rectform(test)$
Evaluation took 0.1360 seconds (0.2420 elapsed) using 302.578 KB.
(%i6) abs(test)$
Evaluation took 0.3120 seconds (0.4120 elapsed) using 2.536 MB.
Then I have measured the time to get the plots. Surprisingly, the plot
with the absolute value now is much faster:
(%i7) plot3d(sqrt(realpart(test)^2
+imagpart(test)^2),[ky,-3,3],[kz,-3,3]);
Evaluation took 119.8990 seconds (122.6900 elapsed) using 3259.698 MB.
(%o7) false
(%i8) plot3d(abs(test),[ky,-3,3],[kz,-3,3]);
Evaluation took 54.8320 seconds (56.3300 elapsed) using 628.454 MB.
(%o8) false
I have tried the testsuite with the modified function absarg and I have
got no problems. I will do some further tests.
Dieter Kaiser