As indicated previously, facilities exist for the manipulation of complex as well as real and integer quantities. complex quantities are stored as a pair of real numbers in consecutive locations (the real and imaginary parts respectively). The address of the complex quantity is that of the real part.
All quantities must be declared before they are referred to. For example:-
real R1, R2, R3 complex z complex array P(1:10), Q(1:10,1:10)
causes 3 locations to be reserved for R1, R2, R3, 2 for z, 20 for P and 200 for Q.
The following standard functions are added to those previously given:-
re(z) (real part of z) im(z) (imaginary part of z) mag(z) (modulus of z) arg(z) (argument of z - in radians) conj(z) (complex conjugate of z)
The argument z may be any [EXPR] (in the complex sense as described below) The functions
csin, ccos, ctan, cexp, clog, csqrt
have complex [EXPR]'s as arguments and yield results of complex type. For example if z = x + iy, cexp(z) = exp(x)(cos(y) + i sin(y)) In the case of clog and csqrt it is the principal value which is computed, i.e., the value for which the argument θ lies in the range -π≤θ<π
The arithmetic expression [EXPR] is still of the form
[±'][OPERAND][OPERATOR][OPERAND][OPERATOR] ........ [OPERAND]
but [OPERAND] is now expanded to be
[VARIABLE],[CONSTANT],([EXPR]),|[EXPR]|,[FUNCTION] or i
Here i is a delimiter denoting the i (or j) of complex algebra notation.
Examples of this more general expression are:-
(V*conj(I) - I*conj(V))/(2i) (Z1Z2 + Z2Z3 + Z3Z1)/Z3 Y(1,2) + csin(conj(Y(2,1))) R0*(1 + 2iQ0d) i
When a complex number is written out explicitly (say x + iy), then it is regarded as 3 operands (x,i and y) connected by the two operators + and (implied) *. Thus if the brackets were omitted from the denominator in the first example it would mean
((V*conj(I) - I*conj(V))/i)2
The form of an assignment instruction remains
[VARIABLE] = [EXPR]
but [VARIABLE] now includes complex scalars and complex array elements. For example:-
Z = Z1Z2/(Z1 + Z2) Y = G + i2πf*c A(p,q) = 2csin(2πz) R = R1 + re(Z) P = ½re(V*conj(I) + I*conj(V))
1. Just as real quantities may not appear on the r.h.s. of an integer assignment (except as arguments of integer functions), so complex quantities may not appear in real or integer expressions. However, the functions
re(z), im(z), mag(z), arg(z)
convert from complex to real quantities and may therefore appear on the r.h.s. of a real assignment. In fact any function whose value is real regardless of its arguments may be used in a real expression (just as any integer function, regardless of its argument, may appear in an integer expression). Thus if X and B are real and Y complex then:-
X = B + im(Y)
is valid.
2. re(z) and im(z) are actual locations in the store and can therefore be used on the l.h.s. of an instruction (whose mode is then real). For example:-
re(z) = sqrt(2) im(y) = 5 + im(z1)
However, mag(z) and arg(z), even though they do define z, are not locations in the store and cannot be used on the l.h.s. If a complex quantity is being evaluated by means of the evaluation of its magnitude (m) and argument (a), the assignment is done by
z = m*(cos(a) + i sin(a)) or z = m*cexp(ia)
In conditional operators, [EXPR]'s must be real (in the sense of note 1 of the previous section ). Hence the following are legitimate:-
if arg (z) ≥ π/2 then -> 3 3 case mag(z) ≥ 1 :
Since routines and functions are allowed to operate on complex quantities, the parameter types have been expanded to include
Formal parameter type | Corresponding actual parameter |
---|---|
complex name | name of a complex variable |
complex | any expression (which will be evaluated as if for a complex assignment) |
complex array name | name of a complex array |
complex array | name of a complex array |
The routine types [RT] have also been expanded to include complex fn. As an example we will rewrite the function routine for the polynomial
a(m) + a(m+1)x+.......... + a(m+n)x↑n
assuming x and the coefficients a(i) to be complex.
complex fn poly (complex arrayname a, complex x, integer m,n) integer i ; complex y y = a(m+n) ; result = y if n = 0 cycle i = m+n-1, -1, m y = y*x + a(i) repeat result = y end
Data is punched in the form
[REAL PART] ± i [IMAGINARY PART]
but the individual parts can be punched in any acceptable 'real' form. Both parts must be punched however. For example:-
3+i4 0+i1 -0.5+i 0 1.17α3 -i2.13α4
They may be read by the instruction
read(Z1,Z2,Z3,Z4)
The permanent routines
print complex(complex z, integer m,n) print complex fl(complex z, integer n)
print the value of z in the form
[REAL PART] ± i [IMAGINARY PART]
the individual parts being printed with the aid of the corresponding real routines, 'print' and 'print fl', using the same digit layout parameters. For 7-hole tape this form of output is compatible with the format for punching complex data.
read(re(z),im(z))