problems with abs() and cabs()



The approach using "cabs" is probably not ideal.

The purpose of cabs is to produce a *symbolic expression* for the complex
absolute value.  In this case, that expression is huge.  (I think cabs could
also be improved, but that's another matter...)

The approach using 'abs' should work much better in this case, except that
someone has unthinkingly changed abs to call cabs, which is of course a
disaster in this case.

By the way, Maxima will work better in general if you use rational number
exponents (2/3) rather than floating-point exponents (0.6666666666).

             -s

On Thu, Jan 7, 2010 at 5:42 AM, Stanislav Maslovski <
stanislav.maslovski at gmail.com> wrote:

> Hi everyone,
>
> Doing some calculations I noticed that there is something wrong with
> imlementation of abs() and cabs(). Basically, in the code below I can
> calculate and plot sqrt(re^2 + im^2), but I cannot do it with abs(),
> nor with cabs(): it never finishes and Maxima does not react to the
> keyboard interrupt either. Maybe, this triggers a bug in gcl?
>
> I run this version of maxima (on Debian sid):
>
> Maxima 5.20.1 http://maxima.sourceforge.net
> using Lisp GNU Common Lisp (GCL) GCL 2.6.7 (a.k.a. GCL)
>
> ========================================================
>
> eps : [1,2];
>
> mu : [1,1];
>
> n : sqrt(eps*mu);
>
> vc : [0,0.5];
>
> epst : eps*(1-vc^2)/(1-n^2*vc^2);
>
> mut : mu*(1-vc^2)/(1-n^2*vc^2);
>
> a : vc*(n^2-1)/(1-n^2*vc^2);
>
> kxe : -%i*sqrt(-k0^2*eps*mut+eps/epst*(kz+k0*a)^2+ky^2);
>
> kxh : -%i*sqrt(-k0^2*mu*epst+mu/mut*(kz+k0*a)^2+ky^2);
>
> betae : k0*kxe*epst/(k0^2*epst*mut-(kz+k0*a)^2);
>
> betah : k0*kxh*mut/(k0^2*epst*mut-(kz+k0*a)^2);
>
> alpha : -ky*(kz+k0*a)/(k0^2*epst*mut-(kz+k0*a)^2);
>
> a1 : part(alpha,1); a2 : part(alpha,2);
>
> be1 : part(betae,1); be2 : part(betae,2);
>
> bh1 : part(betah,1); bh2 : part(betah,2);
>
> denom : (a1-a2)^2+(be1+be2)*(bh1+bh2);
>
> Ree : -((a1-a2)^2-(be1-be2)*(bh1+bh2))/denom;
>
>
> plot3d(sqrt(realpart(subst(k0=%i,Ree))^2+imagpart(subst(k0=%i,Ree))^2),[ky,-3,3],[kz,-3,3]);
>
> plot3d(cabs(subst(k0=%i,Ree)),[ky,-3,3],[kz,-3,3]);
>
> plot3d(abs(subst(k0=%i,Ree)),[ky,-3,3],[kz,-3,3]);
>
>
> --
> Stanislav
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>