Description : | It adds only two routines: to_r() and to_p(). These routines
make it easy to work with complex numbers in the polar (or
phasor) form often used by electrical engineers. In polar
form a complex number is written as a (magnitude, angle) pair
where the angle is in degrees measured counterclockwise (CCW) from
the positive real axis. In engineering texts the notation
mag /_ angle is often used, so 10 /_ 45 would represent the
complex number with magnitude 10 at a 45 degree CCW from the
real axis. to_r(10,45) converts this to standard form and
gives 7.07+7.07i.
The routines define and work with two matrix "polar forms".
In the first form the magnitudes and angles are in adjacent
columns of a single matrix. In the second form the magnitudes
and angles are in separate matrices. The to_r() example at
the end of the previous paragraph used the second form. The
same result can be obtained using the first form via
to_r([10 45]).
to_r() is used to convert polar form numbers or matrices
to standard form:
-->// Create a 2x2 impedance matrix.
-->// The impedances are given in a mix of polar and standard forms.
-->Z = [to_r(100, 45) 200+%i*200; to_r(150,90) 200];
-->// Create a voltage vector V(1) = 50 /_0, V(2) = 100 /_ -30
-->V = to_r([50 0; 100 -30]);
Complex matrices should always be in standard form for computation.
to_p() is normally used only at the end of a computation to show
a result in polar form:
-->// Calculate currents corresponding to previous Z and V
-->I = Z\V
I =
! - 0.2947621 - 0.2717314i !
! 0.2292141 - 0.0289284i !
-->to_p(I)
ans =
! 0.4009023 - 137.32806 !
! 0.2310324 - 7.1930998 !
In this example I(1) = -0.295 - 0.272i = 400 mA /_ -137.3 degrees and
I(2) = 0.229 - 0.029i = 231 mA /_ -7.2 degrees.
|