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 ,其中 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 maxon::Complex<maxon::Float> complexB(1, -3);

// 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 const maxon::Complex<maxon::Float> log = complexA. GetLog () iferr_return ;

// 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); maxon::Complex<maxon::Float> complexB(6, 8); 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 maxon::Complex<maxon::Float> complexA; maxon::Complex<maxon::Float> complexB; maxon::Complex<maxon::Float> complexC;

// 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 maxon::WriteDocument (url, maxon::OPENSTREAMFLAGS::NONE , fileID, savedComplex, maxon::IOFORMAT::JSON ) iferr_return ;

// read from file maxon::Complex<maxon::Float> loadedComplex; maxon::ReadDocument (url, fileID, loadedComplex) iferr_return ;

延伸阅读

maxon::ReadDocument
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())
定义: io.h:35
maxon::Complex::SetPolar
void SetPolar(const T len, const T phase)
Initialize Complex number by given polar coordinates.
定义: complex.h:273
maxon::Complex::GetNormalized
Complex GetNormalized() const
定义: complex.h:300
maxon::String
定义: string.h:1197
maxon::Complex::SetPhase
void SetPhase(const T phase)
Set polar phase (angle) in the Argand plane.
定义: complex.h:268
maxon::Complex::SetLength
void SetLength(const T len)
Set polar length (magnitude) in the Argand plane.
定义: complex.h:261
maxon::Id
定义: apibaseid.h:250
iferr_return
#define iferr_return
定义: resultbase.h:1434
maxon::OPENSTREAMFLAGS::NONE
@ NONE
No flags set.
maxon::Float
Float64 Float
定义: apibase.h:193
DiagnosticOutput
#define DiagnosticOutput(formatString,...)
定义: debugdiagnostics.h:166
maxon::Url
定义: url.h:819
maxon::Complex::GetConjugate
Complex GetConjugate() const
定义: complex.h:308
maxon::IOFORMAT::JSON
@ JSON
maxon::Complex::GetSqrt
Complex GetSqrt() const
定义: complex.h:313
maxon::Complex::SetExp
void SetExp(const T x)
set Complex number according to e^(i*x)
定义: complex.h:279
maxon::WriteDocument
Result< void > WriteDocument(const Url &url, OPENSTREAMFLAGS flags, const Id &id, const T &object, IOFORMAT format=IOFORMAT::DEFAULT, const DataDictionary &dict=DataDictionary())
定义: io.h:67
maxon::Complex::ToString
String ToString(const FormatStatement *formatStatement=nullptr) const
定义: complex.h:359
PI05
static constexpr Float64 PI05
floating point constant: 0.5 * PI
定义: apibasemath.h:124
maxon::Complex
定义: complex.h:25
maxon::Complex::GetLog
Result< Complex > GetLog() const
定义: complex.h:324

Copyright  © 2014-2025 乐数软件    

工业和信息化部: 粤ICP备14079481号-1