RF21 Freeware Function Reference home

Complex Arithmetic


While RF21 has no separate complex data type, it has specialized user defined functions that will treat pairs of real numbers as complex numbers and manipulate them. The first item of such a number pair is always looked upon as the real part, the second as imaginary part. Complex vectors and matrices are stored as sequences of such number pairs.
To create a complex number, it suffices to write a pair of reals, separated by commas. Thus 0,1  will be the imaginary unit "i" and 1,0 the real unit "1". "Converting" a real number to the complex format requires just appending a zero, nevertheless there is a function complex#2(r) to do this, its output is of course r,0. Extraction of real and imaginary part from a complex number is done by functions Re(r,i) and Im(r,i) allthough one could simply use nth(1,...) and nth(2,...) to do this. Some of complex arithmetic is done by standard vector functions such as plus##(...) and minus##(...) for addition and subtraction, and norm2(...) for computing the absolute value of a complex number. For instance, there is plus##(3,7,2,-5) = 5,2. For conjugation of complex numbers (and vectors hereof) use the function conj##(...)
Complex numbers are sometimes written in Euler form (or polar form) consisting of their length as a vector followed by an oriented angle in radians, which is measured against the positive Re-axis. The conversion to Euler form and back is done by functions eulertoc#2() and ctoeuler#2().

The rest of complex arithmetics is done by the specialized functions of the following table.

cminus#2(r,i)
cminus#2(2,-3) = -2,3
Takes a complex number times -1.
COMPLEX.LIB
ctimes#2(r,i,R,I)
ctimes#2(1,5,2,-1) = 7,9
Multiplication of two complex numbers
COMPLEX.LIB
cdivide#2(r,i,R,I)
cdivide#2(1,6,4,3) = 0.88, 0.84
Division of two complex numbers
COMPLEX.LIB
crez#2(r,i)
crez#2(4,3) = 0.16, -0.12
The reciprocal of a complex number (same as cdivide#2(1,0,r,i))
COMPLEX.LIB
cquad#2(r,i)
cquad#2(4,3) = 7,24
The square of a complex number
COMPLEX.LIB
ckubik#2(r,i)
ckubik#2(4,3) = -44,117
The cube of a complex number
COMPLEX.LIB
csqr#2(r,i)
csqr#2(4,3) = 2.121320344, 0.70710678
The square root. Of the two possible choices, the one preserving the sign of the imaginary part
COMPLEX.LIB
ccur#2(r,i)
ccur#2(4,3) = 1.6707882, 0.36398424
The cubic root. Returns negative reals for negative real input. Otherwise, returns the root which is closest to (1,0).
COMPLEX.LIB
cpower#2(r,i,R,I)
cpower#2(4,3,4,0) = -527, 336
The power of two complex numbers
COMPLEX.LIB
cpower#2(r,i,n)
cPower(4,3,4) = -527, 336
The power of a complex number with an integer exponent. Implementation relying only on complex multiplication. Unlike cpower#2, enjoys the benefit of uniqueness.
COMPLEX.LIB
cturn120#2(r,i)
cturn120#2(1,0) = -0.5, 0.8660254
Performs a 120° counterclockwise turn in the complex plane.
COMPLEX.LIB
cturn240#2(r,i)
cturn240#2(1,0) = -0.5, -0.8660254
The same, clockwise.
COMPLEX.LIB
cexp#2(r,i)
cexp#2(1,pi) = -2.718281828, 0
The complex exponential function
COMPLEX.LIB
cln#2(r,i)
cln#2(0,1) = 0, 1.57079633
The complex natural logarithm
COMPLEX.LIB
ccos#2(r,i)
ccos#2(0,1) = 1.543080635, 0
The cosine of a complex number
COMPLEX.LIB
csin#2(r,i)
csin#2(0,1) = 0, 1.17520119
The sine of a complex number
COMPLEX.LIB

Excessive use of this complex arithmetic has been made within functions calculating polynomial roots. For polynomials up to grad 4, computing their complex roots is supported (see the polynomial page). For complex eigenvalues of real matrices up to size 4x4, see the matrix page.

Fraction Arithmetic

Like most pocket calculators, RF21 will manipulate fractions. They should be given to specialized user functions either in the form of integer pairs with the second number unequal 0, such as 11,3 standing for the pure fraction 11/3. Or else, in the form of three integers like 2,1,8 meaning the mixed fraction 2+1/8. Functions expecting pure fractions have names beginning with a single f, functions expecting mixed fractions have a double f. There are functions ftoff#3(a,b) to convert from pure to mixed fractions and fftof#2(a,b,c) to convert the other way. Concerning placements and meaning of minus signs, there are the following conventions: If a pure fraction is negative, its numerator will be output negative and its denominator positive. If a mixed fraction is negative, both its integer part and the fraction numerator will carry the minus sign: For instance, -2.125 = - (2 1/8) will be output as -2, -1, 8. Moreover, fractions will be reduced when in normalized form, and in mixed normalized fractions, the numerator must be smaller than its denominator. Functions fnormalize#2(a,b) and ffnormalize#3(a,b,c) convert fractions to normalized form, so they will also reduce fractions. All of the following arithmetic functions return their results in normalized form:


fplus#2(a,b,A,B)
fplus#2(1,3,1,2) = 5, 6
Addition of pure fractions
UTILS.LIB
fminus#2(a,b,A,B)
fminus#2(1,3,1,2) = -1, 6
Subtraction of pure fractions
UTILS.LIB
ftimes#2(a,b,A,B)
ftimes#2(2,3,-3,7) = -2, 7
Multiplication of pure fractions
UTILS.LIB
fdivide#2(a,b,A,B)
fdivide#2(1,3,1,2) = 2, 3
Division of pure fractions
UTILS.LIB
ffplus#3(a,b,c,A,B,C)
ffplus#3(1,1,4,7,1,3) = 8, 7, 12
Addition of mixed fractions
UTILS.LIB
ffminus#3(a,b,c,A,B,C)
ffminus#2(1,1,4,7,1,3) = -6, -1, 12
Subtraction of mixed fractions
UTILS.LIB
fftimes#3(a,b,c,A,B,C)
fftimes#2(1,1,4,7,1,3) = 9, 1, 6
Multiplication of mixed fractions
UTILS.LIB
ffdivide#3(a,b,c,A,B,C)
ffdivide#2(1,1,4,7,1,3) = 0, 15, 88
Division of mixed fractions
UTILS.LIB
ffrez#3(a,b,c)
ffrez#2(0,-15,88) = -5, -13, 15
Finds the reciprocal of a mixed fraction
UTILS.LIB