|
  
Complex Numbers
There is a branch of mathematics that deals with numbers
consisting of both real and imaginary components--complex
numbers. For example, in the real domain, the square root of
negative one is undefined. That is, there is no real number that
can be multiplied by itself to get -1. However, in the world of
complex math, there is a solution to this problem and it is the
unit imaginary number called i.
Complex numbers have both a real and imaginary component. In
DScript, you enter complex numbers by typing an arithmetic
expression using the primitive I. The
number 2+3i is entered as 2+3*I
or simply 2+3I (multiplication is
implied). Complex numbers can also be created using formulas that
return complex results; e.g., the expression sqrt(-1) will return i.
The two numeric parts of a complex number are each represented
by 8-byte floating-point numbers and are stored as a single data
item.
There is nothing special you must do to create equations
supporting complex math. Almost all mathematical primitives that
support simple real numbers also support complex numbers. Each
primitive detects the type of input data you supply and adapts
its function to support that data.
Like every other basic capability in DScript, you can simply
ignore the existence of complex numbers if you don't want to use
them. However, if you do use complex numbers in work you
routinely perform, you will appreciate the ease with which they
can be applied in DScript. There is no difference between the way
you create formulas using complex and simple real numbers.
The following tree, which calculates the root to a quadratic
equation (ax^2+bx+c=0), works equally well if the result
is real or complex.
All primitives are designed to accept complex numbers if
possible. Complex inputs simply make no sense for some
primitives; but for all others, the primitive will adapt its
function to process complex inputs.
A few primitives are designed explicitly for use with complex
numbers. Specifically, use the real
and imag primitives to extract
the real and imaginary components from a complex number. Use abs and arg
to convert complex numbers into their polar equivalent.
You can turn complex number support on/off by clicking System
Options in the Tools menu and choosing the appropriate
option on the Calculation page.
There is very little performance penalty for enabling complex
math. However, you might not want to support complex numbers so
that certain types of errors will be detected. For example, if
your application includes the expression sqrt(-1)
and complex number support is enabled, DScript will simply return
the result i. However, if you never expected to be working
in the complex domain, it might be better to disable complex math
so that DScript will issue an error message in this situation.
|