plotting modulus of complex function



On 05/03/2012 12:18 PM, Bart Vandewoestyne wrote:
> sing wxMaxima 0.8.5, I'm trying to plot the modulus of two complex
> function on the positive real axis.:
>
> d: 1e-3$
> f: 10^6$
> omega: 2*%pi*f$
> epsilon[0]: 8.8541878176e-2$
> mu[0]: 4*%pi*10^(-7)$
> v[0]: 1/sqrt(epsilon[0]*mu[0])$
> k[0]: 2*%pi*f/v[0]$
> epsilon[sub]: 12.9*epsilon[0]$
>
> Z_TE_sub(s) := %i*omega*mu[0]/(k[0]*sqrt(s^2-epsilon[sub]/epsilon[0]))$
> Z_TE_0(s) := %i*omega*mu[0]/(k[0]*sqrt(s^2-1))$
> Z_TM_sub(s) :=
> (k[0]*sqrt(s^2-epsilon[sub]/epsilon[0]))/(%i*omega*epsilon[sub])$
> Z_TM_0(s) := (k[0]*sqrt(s^2-1))/(%i*omega*epsilon[0])$
> vTE(s) := (Z_TE_sub(s)*Z_TE_0(s))/(Z_TE_sub(s) +
> Z_TE_0(s)*coth(d*k[0]*sqrt(s^2-epsilon[sub]/epsilon[0])))$
> vTM(s) := (Z_TM_sub(s)*Z_TM_0(s))/(Z_TM_sub(s) +
> Z_TM_0(s)*coth(d*k[0]*sqrt(s^2-epsilon[sub]/epsilon[0])))$
> Gm(s) := -vTE(s)/(2*%pi)$
> Ge(s) := (vTE(s)-vTM(s))/(2*%pi*s*k[0])$
>
> plot2d(float(abs(Gm(s))), [s, 1e-1, 1e3]);
> plot2d(float(abs(Ge(s))), [s, 1e-1, 1e3]);
>
>
> Unfortunately, this fails.  I get the error: 
Hi,
the function used to obtain the modulus of a complex number is cabs() 
and not abs(). However, in the command plot2d(float(abs(Ge(s))), [s, 
1e-1, 1e3]) cabs would give you a very long expression in terms of s 
which might get your system stuck. I suggest that you first compute the 
floating-point value for a given s,
then compute cabs and only then pass the result. Also, the notation 
epsilon[0] might look cute in Wxmaxima,
but it means defining an array which you really don't need and will add 
to the computational complexity.
You might want to try something such as:

d: 1e-3$
f: 1e6$
omega: 2*%pi*f$
epsilon0: 8.8541878176e-2$
mu0: 4*%pi*1e-7$
v0: 1/sqrt(epsilon0*mu0)$
k0: 2*%pi*f/v0$
epsilonsub: 12.9*epsilon0$

Z_TE_sub(s) := %i*omega*mu0/(k0*sqrt(s^2-epsilonsub/epsilon0))$
Z_TE_0(s) := %i*omega*mu0/(k0*sqrt(s^2-1))$
Z_TM_sub(s) :=
(k0*sqrt(s^2-epsilonsub/epsilon0))/(%i*omega*epsilonsub)$
Z_TM_0(s) := (k0*sqrt(s^2-1))/(%i*omega*epsilon0)$
vTE(s) := (Z_TE_sub(s)*Z_TE_0(s))/(Z_TE_sub(s) +
Z_TE_0(s)*coth(d*k0*sqrt(s^2-epsilonsub/epsilon0)))$
vTM(s) := (Z_TM_sub(s)*Z_TM_0(s))/(Z_TM_sub(s) +
Z_TM_0(s)*coth(d*k0*sqrt(s^2-epsilonsub/epsilon0)))$
Gm(s) := cabs(float(-vTE(s)/(2*%pi)))$
Ge(s) := cabs(float((vTE(s)-vTM(s))/(2*%pi*s*k0)))$

Your functions have several steep spikes, so you might have to view separate
parts of the frequency domain in separate plots, in order to see the 
separate spikes.
For instance:

plot2d(Ge, [s,0.1,3.5]);
plot2d(Ge, [s,1.1,3.5]);

and notice that I have called Ge by name, rather than Ge(s), which would 
pass a huge expression of
s to plot2d.

Regards,
Jaime