Complex Numbers

Octave defines its own complex data structure in the header oct-cmplx.h. The programmers propose: ``By using this file instead of `complex.h', we can easily avoid buggy implementations of the standard complex data type (if needed).'' Thus the data structure is defined as

typedef std::complex<double> Complex

To define a complex number, e.g. 0.7+0.3i, within your program use

Complex number = Complex (0.7, 0.3);

The following useful functions are available to manipulate the above given complex data structure.

// real part
double real (const Complex& z)
// imaginary part
double imag (const Complex& z)
// absolute value
double abs (const Complex& z)
// argument of the complex number
double arg (const Complex& z)
// complex conjugate complex number
Complex conj (const Complex& z)
// complex exponential function
Complex exp (const Complex& z)
// power n of a complex number
Complex pow (const Complex& z, int n)
// square root of a complex number
Complex sqrt (const Complex& z)