CoWeb

find:
goto:
home

history
links from
printable

login
















Complex Arithmetic Script
Webb - all rights reserved - ©2004
spacer
Author - Ray Franco, Ph.D.,
Email: r.a.franco@ieee.org
Webpage:

Summary: Ten functions (degrees or radians)  with extensive help and
argument checking.

Instructions: Includes the following complex math functions:
rectangular-to-polar,
polar-to-rectangular, clear complex, conjugate, inverse, addition,
subtraction, multiplication, division, and swap complex numbers.
For functions that require a single complex argument, X+iY, X should
be in stack position 1 and Y in position 2. For functions that require two
complex arguments, X2+iY2 and X1+iY1, X1 should be in stack
position 1, Y1 in position 2, X2 in position 3, and Y2 in position 4.
P->R function assumes the magnitude is in stack position 1 and the
angle in position 2. The results are returned using the same convention.
Multiplication and division are preformed by first converting the number
to polar form.

Why another complex number scrip: Perry's doesn't work in radians,
doesn't provide help, jumbles the stack if the right number of arguments
are not entered, and it's not efficient. Katsumata's rectangle-to-polar
function gives the wrong angle [atan(Re/Im)], and it bombs out when the
imaginary part is zero. Hey, this stuff is not easy, and these are the guys
that inspired me. We all owe them thanks.        


Code:

RPN.2  \Complex #\
[p] g10<(1A4*:0)g3g3g1b0>(/A:d10<1A2*r2(n))+k32Pr22P+s;
[r] g2g2r2i*k3r2o*;
[c] r2nr2;
"Complex #"
"Complex #: ver 1.00 12-5-99\Ray Franco Ph.D.,\r.a.franco@ieee.org";
~
"conj:  X+iY-->X-iY"?2Cc;
"inv: X+iY-->1(X+iY)"?2CpCctCr;
"swp: (X2+iY2),(X1+iY1)\    -->(X1+iY1),(X2+iY2)"?2k4k4;
~
"+:    (X2+iY2)+(X1+iY1)\-->{(X2+X1)+i(Y2+Y1)}"?4k4r3+k3+;
"-:    (X2+iY2)-(X1+iY1)\-->{(X2-X1)+i(Y2-Y1)}"?4r2r4r2-k3-;
"x:   (X2+iY2)*(X1+iY1)-->\(X1X2-Y1Y2)+i(X1Y2+X2Y1)"?4Cpk4k3Cpk4+k3*Cr;
":     
(X2+iY2)(X1+iY1)-->\{(X1X2+Y1Y2)+i(X1Y2-X2Y1)}\(X1X1+Y1Y1)"?4Cpk4k4Cpr3/k3r2-r2Cr;

~
"r>p:  (iY,X)-->\{atan(YX), sqrt(XX+YY)}"?2Cp;
"p>r:\(\248,M)-->(i M sin\370, M cos\248)"?2Cr;
"clrXY: (X2+iY2),(X1+iY1)\       -->(X2+iY2)"?2d1d1;


0.0195 secs

top of page

Webb - all rights reserved - ©2004
powered by Spinneret 0.10