COMPLEX NUMBERS

Complex numbers are used in many scientific areas where they have to be subjected to various mathematical operations. This is only a very brief introduction to that subject.


Complex Number Plane

Complex numbers are made up of two components: a real component and an imaginary component. It can be represented by the following formula, the letter "z" often being used as a symbol for complex numbers:

z = a + bi

where:
a = coefficient of the real component
b = coefficient of the imaginary component
i = sqrt(-1)

A complex number is also often simply defined as z(a,b), the first parameter being by convention the coefficient of the real component and the second parameter being the coefficient of the imaginary component.

As indicated in the above diagram, complex numbers can be represented on a two-dimentional plane, the real component being on the X axis and the imaginary component on the Y axis. Those are called cartesian coordinates. As observed, the same point on the plane can also be represented by the lenght of the vector from the origin and the angle with the X axis. Those would be called polar coordinates. The formula in polar coordinates would be:

z = r × eθi

where:
r = length of the vector from the origin
e = the Napierian constant 2.71828...
θ = the angle with the X axis (in radians)
i = sqrt(-1)

It is also often simply defined as z(r,θ) in polar coordinates.

You will notice that when θ=0, the complex nunber would be equivalent to the real number. The angle is thus measured from the x-axis and would be positive in the anti-clockwise direction and could be expressed in the range of 0 to +2π. Conversely, it could be expressed in the range of 0 to -2π going in the clockwise direction. Generally, the functions of the library would return values in the 0 to +π above the x-axis, and 0 to -π below the x-axis.

Using basic trigonometry, polar coordinates can easily be converted to cartesian coordinates according to the following equations:
    a = r × cos(θ)
    b = r × sin(θ)

Conversely, using basic geometry and trigonometry, cartesian coordinates are easily converted to polar coordinates according to the following equations:
    r = sqrt(a²+b²)
    θ = atan(b/a)

You will notice that regardless of the signs of the a and b components, their square will always be positive along with the square root of their sum. The length of the vector r would thus always be positive when converting from cartesian to polar coordinates. If a negative vector was specified with a given angle for polar coordinates, it would be equivalent to a positive vector going in the opposite direction, i.e.
z(-r,θ) = z(r,θ+π)

For proper conversion from cartesian to polar coordinates, it is also important to realize that an atan(a/-b) would return the same value as an atan(-a/b) if only the quotient is provided to an ATAN function, although those coordinates would be in opposite quadrants. In assembly, the correct angle will be returned if the a and b components are loaded individually on the FPU before using the fpatan instruction.

The above conversions from one coordinate type to the other are often necessary because some mathematical operations do not lend themselves easily to one or the other. For example, additions and subtractions must be done with cartesian coordinates, computing a logarithm is easier with polar coordinates, while the antilog uses cartesian coordinates. Many functions require complicated coding.

A library of mathematical functions has thus been prepared to help the assembly programmer until he can code those functions on his own. The available package contains the library, the include file, a Help file, and the commented source code of each module which also mentions the formula used to obtain the result. A test dialog box program is also included (with source code and resource file) to try each function with user input.

ZLIB v1.1


My son introduced me to fractals several years ago and I have been fascinated by them. Last year, I decided to attempt writing my own fractal generator mainly as an exercise in asm programming and see how fast the basic Mandelbrot could be generated. With time, the program expanded to cover more than the initial Mandelbrot fractal. Many features I would have liked to see in other programs were also included.

The downloadable .zip file contains the executable along with a Help file, a default color map and a set of saved parameters. The source file (currently over 8000 lines) will not be published. However, questions about some of the features or specific parts will gladly be answered on the masmforum.

WMANJUL v2

Other items related to complex numbers may be added to this page in the future.