Complex Manual

maxon::Complex is a MAXON API class used to represent complex numbers and deliver standard mathematical operations. A complex number is a number that can be expressed in the form a + bi, where a and b are real numbers, and i is a solution of the equation x^2 = -1, which is called an imaginary number because there is no real number that satisfies this equation. For the complex number a + bi, a is called the real part, and b is called the imaginary part. Usually complex numbers are represented in a 2D plane known as "complex plane" or "Argand plane" with the abscissa representing the real part and the ordinate representing the imaginary part.

# Creation and initialization

A maxon::Complex instance can be created on the stack and initialized through the proper method using a numerical data type as template:

// This example allocates a few maxon::Complex objects showing the different allocation methods.
// just allocate an zero-valued complex object
const maxon::Complex<maxon::Float> zeroComplex;
// just allocate a complex object defining the real part
const maxon::Complex<maxon::Float> realOnlyComplex(1.4);
// just allocate a complex object defining both real and imaginary part
const maxon::Complex<maxon::Float> fullComplex(1.4, 4);

# Standard operations

The maxon::Complex class delivers a set of standard mathematical operators to perform calculation with complex numbers. The operators delivered are:

// This example shows how to perform simple mathematical operations.
// just allocate a complex object defining the real part
const maxon::Complex<maxon::Float> complexA(2);
// just allocate a complex object defining both real and imaginery part
// sum A to B
complexB += complexA;
// allocate a new complex number and assign the difference between B and A
const maxon::Complex<maxon::Float> complexC = complexB - complexA;
// allocate a new complex number and assign the product between A and C
const maxon::Complex<maxon::Float> complexD = complexA * complexC;
// scale the complexB by a given amount
complexB = complexB * 10;

# Get and Set operations

The maxon::Complex class is provided with a number of get methods to retrieve useful data from a maxon::Complex instance:

// This example shows how to use the "get" methods provided with maxon::Complex.
// just allocate a complex object defining the real part
const maxon::Complex<maxon::Float> complexA(2, 2);
// get the length of the vector representing the complex number on the Argand plane
const maxon::Float lengthValue = complexA.GetLength();
// get the angle (in radians) of the vector representing the complex number on the Argand plane
const maxon::Float angleValue = complexA.GetPhase();
// get the squared length of the vector representing the complex number on the Argand plane
const maxon::Float squaredlengthValue = complexA.GetSquaredLength();
// get the normalized vector representing the complex number on the Argand plane
const maxon::Complex<maxon::Float> normalized = complexA.GetNormalized();
// get the complex conjugate of the vector representing the complex number on the Argand plane
const maxon::Complex<maxon::Float> conjugate = complexA.GetConjugate();
// get the sqrt of the complex number
const maxon::Complex<maxon::Float> sqrt = complexA.GetSqrt();
// get the natural log of the complex number
// get the division of the complex number by the passed value
// NOTE: the result is stored in the calling instance
const maxon::Complex<maxon::Float> divisor(2, 4);
complexB.GetDivision(divisor) iferr_return;

The maxon::Complex class is provided with a number of "set" methods to define a maxon::Complex instance:

// This example shows how to use the "set" methods provided with maxon::Complex.
// just allocate a few zero-valued complex objects
// set the length of the vector representing the complex number on the Argand plane
complexA.SetLength(3);
// set the angle of the vector representing the complex number on the Argand plane
complexA.SetPhase(-PI05);
// set the length and angle of the vector representing the complex number on the Argand plane
complexB.SetPolar(3, PI05);
// set a complex number according to e^(i*x) where x is the passed value
complexC.SetExp(5);

# Conversion

A maxon::Complex instance can be converted to maxon::String using:

// This example shows how to convert a maxon::Complex to maxon::String.
// just allocate a complex object
const maxon::Complex<maxon::Float> complexA(1.45, -0.4);
const maxon::String stringComplex = complexA.ToString(nullptr);
DiagnosticOutput(diagIDString + "complexA: @", complexA);
DiagnosticOutput(diagIDString + "complexA.ToString(): @", stringComplex);

# Utilities

A maxon::Complex instance can be read from and written to disk by serializing the data contained using the conventional functions.

// This example shows how to store and retrieve a maxon::Complex from a file.
const maxon::Complex<maxon::Float> savedComplex(-1, 3);
// file URL
const maxon::Url url = (targetFolder + "complex.txt"_s)iferr_return;
const maxon::Id fileID("net.maxonexample.complex");
// save to file

std::enable_if< GetCollectionKind< T >::value==COLLECTION_KIND::ARRAY, Result< void > >::type ReadDocument(const Url &url, const Id &id, T &object, const DataDictionary &dict=DataDictionary())
Definition: io.h:35
maxon::Complex::SetPolar
void SetPolar(const T len, const T phase)
Initialize Complex number by given polar coordinates.
Definition: complex.h:273
maxon::Complex::GetNormalized
Complex GetNormalized() const
Definition: complex.h:300
maxon::WriteDocument
Result< void > WriteDocument(const Url &url, const Id &id, const T &object, IOFORMAT format=IOFORMAT::DEFAULT, const DataDictionary &dict=DataDictionary())
Definition: io.h:67
maxon::String
Definition: string.h:1197
maxon::Complex::SetPhase
void SetPhase(const T phase)
Set polar phase (angle) in the Argand plane.
Definition: complex.h:268
maxon::Complex::SetLength
void SetLength(const T len)
Set polar length (magnitude) in the Argand plane.
Definition: complex.h:261
maxon::Id
Definition: apibaseid.h:273
iferr_return
#define iferr_return
Definition: resultbase.h:1434
maxon::Float
Float64 Float
Definition: apibase.h:193
DiagnosticOutput
#define DiagnosticOutput(formatString,...)
Definition: debugdiagnostics.h:168
maxon::Url
Definition: url.h:819
maxon::Complex::GetConjugate
Complex GetConjugate() const
Definition: complex.h:308
maxon::IOFORMAT::JSON
@ JSON
maxon::Complex::GetSqrt
Complex GetSqrt() const
Definition: complex.h:313
maxon::Complex::SetExp
void SetExp(const T x)
set Complex number according to e^(i*x)
Definition: complex.h:279
maxon::Complex::ToString
String ToString(const FormatStatement *formatStatement) const
Definition: complex.h:359
maxon::Complex
Definition: complex.h:25
PI05
static const Float64 PI05
floating point constant: 0.5 * PI
Definition: apibasemath.h:148
maxon::Complex::GetLog
Result< Complex > GetLog() const
Definition: complex.h:324