Table of Contents

Struct Complex

Namespace
VirtualLabAPI.Core.Numerics
Assembly
VirtualLabAPI.dll

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.

[Serializable]
public struct Complex
Inherited Members

Constructors

Complex(double)

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

public Complex(double Re)

Parameters

Re double

Real part.

Complex(double, double)

Constructs a complex number with given real and imaginary parts.

public Complex(double Re, double Im)

Parameters

Re double

Real part.

Im double

Imaginary part.

Complex(Complex)

Copy constructor.

public Complex(Complex c)

Parameters

c Complex

Complex number to copy.

Fields

Im

Imaginary part of stored complex number.

public double Im

Field Value

double

Re

Real part of stored complex number.

public double Re

Field Value

double

Undefined

A constant representing an undefined number.

public static readonly Complex Undefined

Field Value

Complex

Zero

A constant containing the neutral element for addition (= (0, 0))

public static readonly Complex Zero

Field Value

Complex

i

The imaginary unit.

public static readonly Complex i

Field Value

Complex

Methods

Abs()

Returns absolute value of current Complex.

public double Abs()

Returns

double

The absolute value, or in physical terms the amplitude

Arg()

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

public double Arg()

Returns

double

The argument (phase) of this complex number.

ArgDifference(Complex, Complex)

Determine the reduced phase difference of two complex numbers

public static double ArgDifference(Complex c1, Complex c2)

Parameters

c1 Complex

Complex number with phase minuend.

c2 Complex

Complex number with phase subtrahend.

Returns

double

Reduced phase difference.

Conjugate(Complex)

Returns conjugate complex number of current Complex.

public static Complex Conjugate(Complex z)

Parameters

z Complex

Complex number to conjugate.

Returns

Complex

Result of operation.

Cos(Complex)

public static Complex Cos(Complex z)

Parameters

z Complex

Returns

Complex

Equals(object)

Compares two complex numbers.

public override bool Equals(object obj)

Parameters

obj object

Complex number to be compared with this complex number.

Returns

bool

true if both complex numbers are equal.

EvaluateFielQuantity(FieldQuantity)

Method to evaluate a specific field quantity of the complex number.

public double EvaluateFielQuantity(FieldQuantity quantityToEvaluate)

Parameters

quantityToEvaluate FieldQuantity

The field quantity which should be evaluated.

Returns

double

The evaluated field quantity.

Exp(Complex)

Returns exponential function of complex number.

public static Complex Exp(Complex c)

Parameters

c Complex

Complex number \(a\).

Returns

Complex

\(e^a\).

FilteredPhase(double, double)

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.
public double FilteredPhase(double maximumAmplitude = 0, double artifactsThreshold = 0.001)

Parameters

maximumAmplitude double

The maximum amplitude. If this optional parameter is not specified, the filtering step (1) is not done.

artifactsThreshold double

The artifacts threshold. 0.1 % is taken as default value.

Returns

double

The phase of the complex value.

FromFieldQuantity(double, FieldQuantity)

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

public static Complex FromFieldQuantity(double value, FieldQuantity fieldQuantity)

Parameters

value double

The double value.

fieldQuantity FieldQuantity

The field quantity into which the value is written.

Returns

Complex

A new complex number.

GetComplexFormat(string)

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).

public static ComplexToStringConversionFormat? GetComplexFormat(string numberString)

Parameters

numberString string

The number string.

Returns

ComplexToStringConversionFormat?

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

GetHashCode()

Returns the hash code for this instance.

public override int GetHashCode()

Returns

int

A 32-bit signed integer that is the hash code for this instance.

InputIsNumericalLarger(Complex)

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

public bool InputIsNumericalLarger(Complex cfForComparison)

Parameters

cfForComparison Complex

The complex number which shall be used for comparison.

Returns

bool

true of input is numerically larger than current instance of the complex number

IsNaN(Complex)

Checks whether either the real or the imaginary is NaN.

public static bool IsNaN(Complex number)

Parameters

number Complex

The complex number to check.

Returns

bool

true if the real or the imaginary part is NaN.

Log(Complex)

Returns natural logarithm of complex number.

public static Complex Log(Complex z)

Parameters

z Complex

Complex number \(a\).

Returns

Complex

\(\ln(a)\).

ModifyComplexPart(ComplexPart)

Returns passed ComplexPart.

public Complex ModifyComplexPart(ComplexPart complexPart)

Parameters

complexPart ComplexPart

ComplexPart to be applied on current Complex.

Returns

Complex

Modified complex number.

Norm()

Returns the squared L2-norm of current Complex.

public double Norm()

Returns

double

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

Parse(string, ComplexToStringConversionFormat)

Parses an string which represents a complex number.

public static Complex Parse(string pureNumberStr, ComplexToStringConversionFormat complexFormat)

Parameters

pureNumberStr string

The string to be converted.

complexFormat ComplexToStringConversionFormat

The format of the complex number. Valid formats are RealImaginary and AmplitudePhase.

Returns

Complex

Complex number.

Parse(string, ComplexToStringConversionFormat, NumberFormatInfo)

Parses an string which represents a complex number.

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

Parameters

pureNumberStr string

The string to be converted.

complexFormat ComplexToStringConversionFormat

The format of the complex number. The SinusCosinus format is not supported. RealImaginary, AmplitudePhase.

doubleFormat NumberFormatInfo

The format of the double-numbers which form the real and imaginary part.

Returns

Complex

Complex number.

Exceptions

ArgumentException

Current complex format is not supported!

ComplexParseException

string is null-string or string is empty or Invalid complex number Format

Polar(double, double)

Returns complex number created by given absolute value and argument.

public static Complex Polar(double abs, double arg)

Parameters

abs double

Absolute value (= amplitude).

arg double

Argument (= phase).

Returns

Complex

New complex object.

Pow(Complex, Complex)

Power function.

public static Complex Pow(Complex basis, Complex exponent)

Parameters

basis Complex

The basis for the power operation.

exponent Complex

The exponent for the power operation.

Returns

Complex

The calculated power value.

Sin(Complex)

public static Complex Sin(Complex z)

Parameters

z Complex

Returns

Complex

Sqrt(Complex)

Returns the square root of a complex number.

public static Complex Sqrt(Complex z)

Parameters

z Complex

Complex number \(a\).

Returns

Complex

\(\sqrt{a}\).

ToString()

Returns a string that represents this instance.

public override string ToString()

Returns

string

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

ToString(int, ComplexToStringConversionFormat?)

Returns formatted string, by default: {Real} + {Imaginary}·i

public string ToString(int numberOfDigits, ComplexToStringConversionFormat? format = null)

Parameters

numberOfDigits int

The number of digits to use for the conversion of the double parts of the complex number.

format ComplexToStringConversionFormat?

Optional enum parameter specifying which format to use. Format can be either

<ul>
<li>{Real} + {Imaginary}·i</li>
<li>{Amplitude}· exp(i·{Phase})</li>
<li>({Real}, {Imaginary})</li></ul>

If this parameter is not specified, the format of complex numbers as specified in the Global Options is used.

Returns

string

Formatted string.

ToString(ComplexToStringConversionFormat)

Returns formatted string, by default: {Real} + {Imaginary}·i

public string ToString(ComplexToStringConversionFormat format)

Parameters

format ComplexToStringConversionFormat

Optional enum parameter specifying which format to use. Format can be either

 <ul>
	<li>{Real} + {Imaginary}·i</li>
	<li>{Amplitude}· exp(i·{Phase})</li>
	<li>({Real}, {Imaginary})</li>
	</ul>

 If this parameter is not specified, the format of complex numbers as specified in the Global Options is used.

Returns

string

Formatted string.

ToString(PhysicalUnit, ComplexToStringConversionFormat, int)

Returns formatted string, either

  • {Real} + {Imaginary}·i
  • {Amplitude} · exp({Phase} · i)
  • ({Real}, {Imaginary})
public string ToString(PhysicalUnit physicalUnit, ComplexToStringConversionFormat ComplexToStringFormat, int ComplexToStringConversionDigits)

Parameters

physicalUnit PhysicalUnit

If 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.

ComplexToStringFormat ComplexToStringConversionFormat

Format of the complex number.

ComplexToStringConversionDigits int

Digits for the conversion of the double numbers of the real and imaginary part (amplitude or phase) of the complex number.

Returns

string

Formatted string.

TryParse(string, out Complex, out ComplexToStringConversionFormat?, NumberFormatInfo)

Tries to parse a string which represents a complex number.

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

Parameters

pureNumberStr string

The string to be converted.

parsedValue Complex

The parsed value if successful.

usedConversionFormat ComplexToStringConversionFormat?

Null if parsing failed. Otherwise the used ComplexToStringConversionFormat which was successful.

doubleFormat NumberFormatInfo

The format of the double-numbers which form the real and imaginary part.

Returns

bool

True if parsing was successful.

Exceptions

ArgumentException

Current complex format is not supported!

ComplexParseException

string is null-string or string is empty or Invalid complex number Format

Operators

operator +(double, Complex)

Adds a real number and a complex number.

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

Parameters

d double

Real number.

z1 Complex

complex number.

Returns

Complex

Sum of both numbers.

operator +(Complex, double)

Adds a complex number and a real number.

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

Parameters

z1 Complex

Complex number.

d double

Real number.

Returns

Complex

Sum of both numbers.

operator +(Complex, Complex)

Adds two complex numbers.

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

Parameters

z1 Complex

First complex number.

z2 Complex

Second complex number.

Returns

Complex

Sum of both complex numbers.

operator /(double, Complex)

Divides a real number by complex number.

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

Parameters

d double

Real number.

z1 Complex

Complex number.

Returns

Complex

Quotient of the two numbers.

operator /(Complex, double)

Divides complex number by real number.

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

Parameters

z Complex

Complex number.

d double

real number

Returns

Complex

Quotient of the two numbers

operator /(Complex, Complex)

Divides complex number by complex number.

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

Parameters

z1 Complex

Complex number.

z2 Complex

Complex number.

Returns

Complex

Quotient of the two numbers.

operator ==(Complex, Complex)

Compares two Complex numbers for equality.

public static bool operator ==(Complex complex1, Complex complex2)

Parameters

complex1 Complex

First complex number.

complex2 Complex

Second complex number.

Returns

bool

true if both numbers are equal.

operator !=(Complex, Complex)

Compares two Complex numbers for inequality

public static bool operator !=(Complex complex1, Complex complex2)

Parameters

complex1 Complex

First complex number.

complex2 Complex

Second complex number.

Returns

bool

true if both numbers are unequal.

operator *(double, Complex)

Multiplies real number with real number.

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

Parameters

d double

Real number.

z Complex

Complex number.

Returns

Complex

Product of the two numbers.

operator *(Complex, double)

Multiplies complex number with real number.

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

Parameters

z Complex

Complex number.

d double

Real number.

Returns

Complex

Product of the two numbers.

operator *(Complex, Complex)

Multiplies two complex numbers.

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

Parameters

z1 Complex

Complex number.

z2 Complex

Complex number.

Returns

Complex

Product of the two numbers.

operator -(double, Complex)

Subtracts complex number from real number.

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

Parameters

d double

Real number.

z1 Complex

Complex number.

Returns

Complex

Difference of the two numbers.

operator -(Complex, double)

Subtracts real number from complex number.

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

Parameters

z1 Complex

Complex number.

d double

Real number.

Returns

Complex

Difference of the two numbers.

operator -(Complex, Complex)

Subtracts two complex numbers.

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

Parameters

z1 Complex

Complex number.

z2 Complex

Complex number.

Returns

Complex

Difference of the two numbers.

operator -(Complex)

Multiplies a complex number with -1.

public static Complex operator -(Complex z)

Parameters

z Complex

The complex number to negate.

Returns

Complex

The negated argument.