Programming Reference for VirtualLab Fusion  2025.1
Loading...
Searching...
No Matches
Complex Struct Reference

This struct holds a complex number.
Operators ( \(a+b\), \(a-b\), \(a*b\), \(a/b\) and \(a^b\)) can be used. Passing \(a\) or \(b\) as double is supported. More...

Inheritance diagram for Complex:

Public Member Functions

double Abs ()
 Returns absolute value of current Complex.
 
double Arg ()
 Returns the argument (phase) of this complex number. The resulting angle is in the range of [-Pi, Pi).
 
 Complex (Complex c)
 Copy constructor.
 
 Complex (double Re)
 Constructs a complex number with given real part. The imaginary part is zero.
 
 Complex (double Re, double Im)
 Constructs a complex number with given real and imaginary parts.
 
double EvaluateFielQuantity (FieldQuantity quantityToEvaluate)
 public support method to evaluate a specific field quantity of the complex number
 
double FilteredPhase (double maximumAmplitude=0, double artifactsThreshold=Globals.MinimumRelativeAmplitude)
 Gets the phase of the complex value. In contrast to the Arg()-method, this method corrects numerical artifacts in the phase. (1) The phase is zero if the amplitude of the complex number is less than threshold times maximum amplitude. (2) The phase value is -π if its imaginary part value {Im} satisfies t⋅Re < -Abs(Im) < 0.
 
bool InputIsNumericalLarger (Complex cfForComparison)
 Method to perform numerical comparison of two complex number. First the amplitudes are compared. If they are equal the phase values are compared.
 
Complex ModifyComplexPart (ComplexPart complexPart)
 Returns passed ComplexPart.
 
double Norm ()
 Returns the squared L2-norm of current Complex.
 
override string ToString ()
 Returns a System.String that represents this instance.
 
string ToString (ComplexToStringConversionFormat format)
 Returns formatted string, by default: {Real} + {Imaginary} \(\cdot\)i.
 
string ToString (int numberOfDigits, ComplexToStringConversionFormat? format=null)
 Returns formatted string, by default: {Real} + {Imaginary} \(\cdot\)i.
 
string ToString (PhysicalUnit physicalUnit, ComplexToStringConversionFormat ComplexToStringFormat, int ComplexToStringConversionDigits)
 Returns formatted string, either.
 

Static Public Member Functions

static double ArgDifference (Complex c1, Complex c2)
 Determine the reduced phase difference of two complex numbers.
 
static Complex Conjugate (Complex z)
 Returns conjugate complex number of current Complex.
 
static Complex Cos (Complex z)
 Returns cosine of complex number.
 
static Complex Exp (Complex c)
 Returns exponential function of complex number.
 
static Complex FromFieldQuantity (double value, FieldQuantity fieldQuantity)
 Creates a complex number from the given double value which is written into the given field quantity.
 
static ? ComplexToStringConversionFormat GetComplexFormat (string numberString)
 Determines the way how a complex number is represented by a string (for example "a + ib" is the RealImaginary format, "a exp ib" is the AmplitudePhase format).
 
static bool IsNaN (Complex number)
 Checks whether either the real or the imaginary is NaN (not a number).
 
static Complex Log (Complex z)
 Returns natural logarithm of complex number.
 
static Complex operator* (Complex z, double d)
 Multiplies complex number with real number.

 
static Complex operator* (Complex z1, Complex z2)
 Multiplies two complex numbers.

 
static Complex operator* (double d, Complex z)
 Multiplies real number with real number.
 
static Complex operator+ (Complex z1, Complex z2)
 Adds two complex numbers.

 
static Complex operator+ (Complex z1, double d)
 Adds a complex number and a real number.
 
static Complex operator+ (double d, Complex z1)
 Adds a real number and a complex number.
 
static Complex operator- (Complex z)
 Multiplies a complex number with -1.
 
static Complex operator- (Complex z1, Complex z2)
 Subtracts two complex numbers.
 
static Complex operator- (Complex z1, double d)
 Subtracts real number from complex number.
 
static Complex operator- (double d, Complex z1)
 Subtracts complex number from real number.

 
static Complex operator/ (Complex z, double d)
 Divides complex number by real number.
 
static Complex operator/ (Complex z1, Complex z2)
 Divides complex number by complex number.

 
static Complex operator/ (double d, Complex z1)
 Divides a real number by complex number.
 
static Complex Parse (string pureNumberStr, ComplexToStringConversionFormat complexFormat)
 Parses an string which represents a complex number.
 
static Complex Parse (string pureNumberStr, ComplexToStringConversionFormat complexFormat, NumberFormatInfo doubleFormat)
 Parses an string which represents a complex number.
 
static Complex Polar (double abs, double arg)
 Returns complex number created by given absolute value and argument.
 
static Complex Pow (Complex basis, Complex exponent)
 public power function of the complex class
 
static Complex Sin (Complex z)
 Returns sine of complex number.
 
static Complex Sqrt (Complex z)
 Return square root of complex number.
 
static bool TryParse (string pureNumberStr, out Complex parsedValue, out ComplexToStringConversionFormat? usedConversionFormat, NumberFormatInfo doubleFormat=null)
 Tries to parse a string which represents a complex number.
 

Public Attributes

double Im
 Imaginary part of stored complex number.
 
double Re
 Real part of stored complex number.
 

Static Public Attributes

static readonly Complex i
 The imaginary unit.
 
static readonly Complex Zero
 A constant containing the neutral element for addition (= (0, 0))
 

Detailed Description

This struct holds a complex number.
Operators ( \(a+b\), \(a-b\), \(a*b\), \(a/b\) and \(a^b\)) can be used. Passing \(a\) or \(b\) as double is supported.

Constructor & Destructor Documentation

◆ Complex() [1/3]

Complex ( double  Re,
double  Im 
)

Constructs a complex number with given real and imaginary parts.

Parameters
ReReal part.
ImImaginary part.

◆ Complex() [2/3]

Complex ( double  Re)

Constructs a complex number with given real part. The imaginary part is zero.

Parameters
ReReal part.

◆ Complex() [3/3]

Complex ( Complex  c)

Copy constructor.

Parameters
cComplex number to copy.

Member Function Documentation

◆ Abs()

double Abs ( )

Returns absolute value of current Complex.

Returns
The absolute value

◆ Arg()

double Arg ( )

Returns the argument (phase) of this complex number. The resulting angle is in the range of [-Pi, Pi).

Returns
Result of operation.

◆ ArgDifference()

static double ArgDifference ( Complex  c1,
Complex  c2 
)
static

Determine the reduced phase difference of two complex numbers.

Parameters
c1complex number with phase minuend
c2complex number with phase subtrahend
Returns
reduced phase difference

◆ Conjugate()

static Complex Conjugate ( Complex  z)
static

Returns conjugate complex number of current Complex.

Parameters
zComplex number to conjugate.
Returns
Result of operation.

◆ Cos()

static Complex Cos ( Complex  z)
static

Returns cosine of complex number.

Parameters
zComplex number \(a\).
Returns
\(\cos(a)\).

◆ EvaluateFielQuantity()

double EvaluateFielQuantity ( FieldQuantity  quantityToEvaluate)

public support method to evaluate a specific field quantity of the complex number

Parameters
quantityToEvaluatethe field quantity which should be evaluated
Returns
the evaluated field quantity

◆ Exp()

static Complex Exp ( Complex  c)
static

Returns exponential function of complex number.

Parameters
cComplex number \(a\).
Returns
\(e^a\).

◆ FilteredPhase()

double FilteredPhase ( double  maximumAmplitude = 0,
double  artifactsThreshold = Globals::MinimumRelativeAmplitude 
)

Gets the phase of the complex value. In contrast to the Arg()-method, this method corrects numerical artifacts in the phase. (1) The phase is zero if the amplitude of the complex number is less than threshold times maximum amplitude. (2) The phase value is -π if its imaginary part value {Im} satisfies t⋅Re < -Abs(Im) < 0.

Parameters
maximumAmplitudeThe maximum amplitude. If this optional parameter is not specified, the filtering step (1) is not done.
artifactsThresholdThe artifacts threshold. 0.1 % is taken as default value.
Returns
The phase of the complex value.

◆ FromFieldQuantity()

static Complex FromFieldQuantity ( double  value,
FieldQuantity  fieldQuantity 
)
static

Creates a complex number from the given double value which is written into the given field quantity.

Parameters
valueThe double value.
fieldQuantityThe field quantity into which the value is written.
Returns
A new complex number.

◆ GetComplexFormat()

static ? ComplexToStringConversionFormat GetComplexFormat ( string  numberString)
static

Determines the way how a complex number is represented by a string (for example "a + ib" is the RealImaginary format, "a exp ib" is the AmplitudePhase format).

Parameters
numberStringThe number string.
Returns
The complex number format. null if the format cannot be determined, e.g. for a real number.

◆ InputIsNumericalLarger()

bool InputIsNumericalLarger ( Complex  cfForComparison)

Method to perform numerical comparison of two complex number. First the amplitudes are compared. If they are equal the phase values are compared.

Parameters
cfForComparisonThe complex number which shall be used for comparison.
Returns
true of input is numerically larger than current instance of the complex number

◆ IsNaN()

static bool IsNaN ( Complex  number)
static

Checks whether either the real or the imaginary is NaN (not a number).

Parameters
numberThe complex number to check.
Returns
TRUE if either the real or the imaginary is NaN.

◆ Log()

static Complex Log ( Complex  z)
static

Returns natural logarithm of complex number.

Parameters
zComplex number \(a\).
Returns
\(\ln(a)\).

◆ ModifyComplexPart()

Complex ModifyComplexPart ( ComplexPart  complexPart)

Returns passed ComplexPart.

Parameters
complexPartComplexPart to be applied on current Complex.
Returns
modified complex number

◆ Norm()

double Norm ( )

Returns the squared L2-norm of current Complex.

Returns
\(Re(this)^2 + Im(this)^2\).

◆ operator*() [1/3]

static Complex operator* ( Complex  z,
double  d 
)
static

Multiplies complex number with real number.

Parameters
zcomplex number
dreal number
Returns
Product of the two numbers

◆ operator*() [2/3]

static Complex operator* ( Complex  z1,
Complex  z2 
)
static

Multiplies two complex numbers.

Parameters
z1complex number
z2complex number
Returns
Product of the two numbers

◆ operator*() [3/3]

static Complex operator* ( double  d,
Complex  z 
)
static

Multiplies real number with real number.

Parameters
zcomplex number
dreal number
Returns
Product of the two numbers

◆ operator+() [1/3]

static Complex operator+ ( Complex  z1,
Complex  z2 
)
static

Adds two complex numbers.

Parameters
z1first complex number
z2second complex number
Returns
sum of both complex numbers

◆ operator+() [2/3]

static Complex operator+ ( Complex  z1,
double  d 
)
static

Adds a complex number and a real number.

Parameters
z1complex number
dreal number
Returns
sum of both numbers

◆ operator+() [3/3]

static Complex operator+ ( double  d,
Complex  z1 
)
static

Adds a real number and a complex number.

Parameters
dreal number
z1complex number
Returns
sum of both numbers

◆ operator-() [1/4]

static Complex operator- ( Complex  z)
static

Multiplies a complex number with -1.

Parameters
zThe complex number to negate.
Returns
the negated argument

◆ operator-() [2/4]

static Complex operator- ( Complex  z1,
Complex  z2 
)
static

Subtracts two complex numbers.

Parameters
z1complex number
z2complex number
Returns
difference of the two numbers

◆ operator-() [3/4]

static Complex operator- ( Complex  z1,
double  d 
)
static

Subtracts real number from complex number.

Parameters
z1complex number
dreal number
Returns
difference of the two numbers

◆ operator-() [4/4]

static Complex operator- ( double  d,
Complex  z1 
)
static

Subtracts complex number from real number.

Parameters
dreal number
z1complex number
Returns
difference of the two numbers

◆ operator/() [1/3]

static Complex operator/ ( Complex  z,
double  d 
)
static

Divides complex number by real number.

Parameters
zcomplex number
dreal number
Returns
Quotient of the two numbers

◆ operator/() [2/3]

static Complex operator/ ( Complex  z1,
Complex  z2 
)
static

Divides complex number by complex number.

Parameters
z1complex number
z2complex number
Returns
Quotient of the two numbers

◆ operator/() [3/3]

static Complex operator/ ( double  d,
Complex  z1 
)
static

Divides a real number by complex number.

Parameters
dreal number
z1complex number
Returns
Quotient of the two numbers

◆ Parse() [1/2]

static Complex Parse ( string  pureNumberStr,
ComplexToStringConversionFormat  complexFormat 
)
static

Parses an string which represents a complex number.

Parameters
pureNumberStrThe string to be converted.
complexFormatThe format of the complex number. Valid formats are RealImaginary and AmplitudePhase.
Returns
Complex number.

◆ Parse() [2/2]

static Complex Parse ( string  pureNumberStr,
ComplexToStringConversionFormat  complexFormat,
NumberFormatInfo  doubleFormat 
)
static

Parses an string which represents a complex number.

Parameters
pureNumberStrThe string to be converted.
complexFormatThe format of the complex number. The SinusCosinus format is not supported. RealImaginary, AmplitudePhase.
doubleFormatThe format of the double-numbers which form the real and imaginary part.
Returns
Complex number.
Exceptions
System.ArgumentExceptionCurrent complex format is not supported!
Exceptions.ComplexParseExceptionstring is null-string or string is empty or Invalid complex number Format

◆ Polar()

static Complex Polar ( double  abs,
double  arg 
)
static

Returns complex number created by given absolute value and argument.

Parameters
absAbsolute value.
argArgument.
Returns
New Complex object

◆ Pow()

static Complex Pow ( Complex  basis,
Complex  exponent 
)
static

public power function of the complex class

Parameters
basisthe basis for the power operation
exponentthe exponent for the power operation
Returns
the calculated power value

◆ Sin()

static Complex Sin ( Complex  z)
static

Returns sine of complex number.

Parameters
zComplex number \(a\).
Returns
\(\sin(a)\).

◆ Sqrt()

static Complex Sqrt ( Complex  z)
static

Return square root of complex number.

Parameters
zComplex number \(a\).
Returns
\(\sqrt{a}\).

◆ ToString() [1/4]

override string ToString ( )

Returns a System.String that represents this instance.

Returns
A System.String that represents this instance, formatted with the format of complex numbers as specified in the Global Options.

◆ ToString() [2/4]

string ToString ( ComplexToStringConversionFormat  format)

Returns formatted string, by default: {Real} + {Imaginary} \(\cdot\)i.

Parameters
formatOptional enum parameter specifying which format to use. Format can be either
  • {Real} + {Imaginary} \(\cdot\)i
  • {Amplitude} \(\cdot\) exp(i \(\cdot\){Phase})
  • ({Real}, {Imaginary})
If this parameter is not specified, the format of complex numbers as specified in the Global Options is used. /param>
Returns
Formatted string.

◆ ToString() [3/4]

string ToString ( int  numberOfDigits,
ComplexToStringConversionFormat format = null 
)

Returns formatted string, by default: {Real} + {Imaginary} \(\cdot\)i.

Parameters
numberOfDigitsThe number of digits to use for the conversion of the double parts of the complex number.
formatOptional enum parameter specifying which format to use. Format can be either
  • {Real} + {Imaginary} \(\cdot\)i
  • {Amplitude} \(\cdot\) exp(i \(\cdot\){Phase})
  • ({Real}, {Imaginary})
If this parameter is not specified, the format of complex numbers as specified in the Global Options is used.
Returns
Formatted string.

◆ ToString() [4/4]

string ToString ( PhysicalUnit  physicalUnit,
ComplexToStringConversionFormat  ComplexToStringFormat,
int  ComplexToStringConversionDigits 
)

Returns formatted string, either.

  • {Real} + {Imaginary} \(\cdot\)i
  • {Amplitude} \(\cdot\) exp({Phase} \(\cdot\) i)
  • ({Real}, {Imaginary})
Parameters
physicalUnitIf the complex number contains/represents a physical unit the corresponding real and imaginary numbers (or amplitude) are returned in measures of the given physical unit. But the corresponding unit-description-string is not appended to the complex number.
ComplexToStringConversionDigitsDigits for the conversion of the double numbers of the real and imaginary part (amplitude or phase) of the complex number.
ComplexToStringFormatFormat of the complex number.
Returns
Formatted string.

◆ TryParse()

static bool TryParse ( string  pureNumberStr,
out Complex  parsedValue,
out ComplexToStringConversionFormat usedConversionFormat,
NumberFormatInfo  doubleFormat = null 
)
static

Tries to parse a string which represents a complex number.

Parameters
pureNumberStrThe string to be converted.
parsedValueThe parsed value if successful.
doubleFormatThe format of the double-numbers which form the real and imaginary part.
usedConversionFormatNull if parsing failed. Otherwise the used ComplexToStringConversionFormat which was successful.
Returns
True if parsing was successful.
Exceptions
System.ArgumentExceptionCurrent complex format is not supported!
Exceptions.ComplexParseExceptionstring is null-string or string is empty or Invalid complex number Format