Code Packages  1
Add-on code processing modules
Public Member Functions | Static Public Member Functions | Properties | List of all members
dsp.Complex Struct Reference

Provides a complex data type and common complex calculations. More...

Public Member Functions

 Complex (double real, double img)
 Initialize a new instance of the Complex type using the specified real and imaginary values More...
 
override bool Equals (object obj)
 
override int GetHashCode ()
 
bool isInfinity ()
 Check if a complex number has infinite value More...
 
bool isNaN ()
 Check if a complex number has a value that is not a number More...
 
double Magnitude ()
 Returns the magnitude (abs) of a complex number More...
 
double Phase ()
 Returns the phase of a complex number in radians More...
 
double Power ()
 Returns the power (absolute square) of a complex number More...
 
override string ToString ()
 Converts the value of a complex number to its equivalent string representation in Cartesian form More...
 

Static Public Member Functions

static Complex Acos (Complex c)
 Returns the angle whose cosine is a complex number More...
 
static Complex Acosh (Complex c)
 Returns the angle whose hyperbolic cosine is a complex number More...
 
static Complex Asin (Complex c)
 Returns the angle whose sine is a complex number More...
 
static Complex Asinh (Complex c)
 Returns the angle whose hyperbolic sine is a complex number More...
 
static Complex Atan (Complex c)
 Returns the tangent of a complex number More...
 
static Complex Atanh (Complex c)
 Returns the angle whose hyperbolic tangent is a complex number More...
 
static Complex Conjugate (Complex c)
 Returns the complex conjugate of a complex number More...
 
static Complex Cos (Complex c)
 Returns the cosine of a complex number More...
 
static Complex Cosh (Complex c)
 Returns the hyperbolic cosine of a complex number More...
 
static Complex Ln (Complex c)
 Returns the natural (base e) logarithm of a complex number More...
 
static Complex Log (Complex c, double a)
 Returns the logarithm of a complex number on the specified real base More...
 
static Complex Log (Complex c, Complex a)
 Returns the logarithm of a complex number More...
 
static Complex Log10 (Complex c)
 Returns the base 10 logarithm of a complex number More...
 
static implicit operator Complex (double value)
 Implicit operator to assign the specified real value with zero imaginary part More...
 
static bool operator!= (Complex A, Complex B)
 Inequality check of two complex numbers More...
 
static Complex operator* (Complex A, Complex B)
 Multiplies two complex numbers More...
 
static Complex operator+ (Complex A, Complex B)
 Adds two complex numbers More...
 
static Complex operator- (Complex A, Complex B)
 Subtracts a complex number from another complex number More...
 
static Complex operator- (Complex A)
 Negates (opposite) a complex number More...
 
static Complex operator/ (Complex A, Complex B)
 Divides a complex number by another complex number More...
 
static bool operator== (Complex A, Complex B)
 Equality check of two complex numbers More...
 
static Complex PolarToRec (double magnitude, double phase)
 Polar-to-rectangular conversion More...
 
static Complex Pow (Complex c, double a)
 Returns the complex number raised to the specified power More...
 
static Complex Reciprocal (Complex c)
 Returns the inverse of a complex number More...
 
static Complex Round (Complex c, int decimals)
 Rounds a complex number to the specified number of fractional digits More...
 
static Complex Sin (Complex c)
 Returns the sine of a complex number More...
 
static Complex Sinh (Complex c)
 Returns the hyperbolic sine of a complex number More...
 
static Complex Sqrt (Complex c)
 Returns the square root of a complex number More...
 
static Complex Tan (Complex c)
 Returns the tangent of a complex number More...
 
static Complex Tanh (Complex c)
 Returns the hyperbolic tangent of a complex number More...
 

Properties

double Img [get, set]
 Gets or sets the imaginary component of the complex number More...
 
double Real [get, set]
 Gets or sets the real component of the complex number More...
 

Detailed Description

Provides a complex data type and common complex calculations.

Constructor & Destructor Documentation

◆ Complex()

dsp.Complex.Complex ( double  real,
double  img 
)

Initialize a new instance of the Complex type using the specified real and imaginary values

If no parameters given, returns a complex number with a zero value (0+0i)


Parameters
realreal part of complex number
imgimaginary part of complex number


Returns
$c=a+bi$


Example
The following example instantiates one complex number (c1) and assigns its value to another complex number (c2).

Complex c1 = new Complex(2.534, -4.895);
Complex c2 = c1;
c2.Real = 10;
Console.WriteLine(c1);
Console.WriteLine(c2);
2.534-4.895i
10-4.895i

Member Function Documentation

◆ Acos()

static Complex dsp.Complex.Acos ( Complex  c)
static

Returns the angle whose cosine is a complex number

Parameters
ccomplex number
Returns
$C=\arccos(c)=-i\ln(c+i\sqrt{1-c^2})$

Example

Complex c = new Complex(1, -1);
c = Complex.Acos(c);
Console.WriteLine(c);
0.904556894302382+1.06127506190504i

◆ Acosh()

static Complex dsp.Complex.Acosh ( Complex  c)
static

Returns the angle whose hyperbolic cosine is a complex number

Parameters
ccomplex number
Returns
$\displaystyle C=arccosh(c)=\ln(c+\sqrt{c^2-1})$

Example

Complex c = new Complex(1, -1);
c = Complex.Acosh(c);
Console.WriteLine(c);
-1.06127506190504-2.23703575928741i

◆ Asin()

static Complex dsp.Complex.Asin ( Complex  c)
static

Returns the angle whose sine is a complex number

Parameters
ccomplex number
Returns
$C=\arcsin(c)=-i\ln(ic+\sqrt{1-c^2})$

Example

Complex c = new Complex(1, -1);
c = Complex.Asin(c);
Console.WriteLine(c);
0.666239432492515-1.06127506190504i

◆ Asinh()

static Complex dsp.Complex.Asinh ( Complex  c)
static

Returns the angle whose hyperbolic sine is a complex number

Parameters
ccomplex number
Returns
$\displaystyle C=arcsinh(c)=\ln(c+\sqrt{c^2+1})$

Example

Complex c = new Complex(1, -1);
c = Complex.Asinh(c);
Console.WriteLine(c);
-1.06127506190504+0.666239432492515i

◆ Atan()

static Complex dsp.Complex.Atan ( Complex  c)
static

Returns the tangent of a complex number

Parameters
ccomplex number
Returns
$\displaystyle C=\arctan(c)=\frac{i}{2}\ln\left(\frac{i+c}{i-c}\right)$

Example

Complex c = new Complex(1, -1);
c = Complex.Atan(c);
Console.WriteLine(c);
1.01722196789785-0.402359478108525i

◆ Atanh()

static Complex dsp.Complex.Atanh ( Complex  c)
static

Returns the angle whose hyperbolic tangent is a complex number

Parameters
ccomplex number
Returns
$\displaystyle C=arctanh(c)=\frac{1}{2}\ln\left(\frac{1+c}{1-c}\right)$

Example

Complex c = new Complex(1, -1);
c = Complex.Atanh(c);
Console.WriteLine(c);
-0.402359478108525+1.01722196789785i

◆ Conjugate()

static Complex dsp.Complex.Conjugate ( Complex  c)
static

Returns the complex conjugate of a complex number

Parameters
ccomplex number
Returns
$C=\overline{c}$

Example

Complex c = new Complex(3, -1);
c = Complex.Conjugate(c);
Console.WriteLine(c);
3+1i

◆ Cos()

static Complex dsp.Complex.Cos ( Complex  c)
static

Returns the cosine of a complex number

Parameters
ccomplex number
Returns
$C=\cos(a+bi)=\cos(a)\cosh(b)-i\sin(a)\sinh(b)$

Example

Complex c = new Complex(1, -1);
c = Complex.Cos(c);
Console.WriteLine(c);
0.833730025131149+0.988897705762865i

◆ Cosh()

static Complex dsp.Complex.Cosh ( Complex  c)
static

Returns the hyperbolic cosine of a complex number

Parameters
ccomplex number
Returns
$\displaystyle C=\cosh(a+bi)=\cosh(a)\cos(b)+i\sinh(a)\sin(b)$

Example

Complex c = new Complex(1, -1);
c = Complex.Cosh(c);
Console.WriteLine(c);
0.833730025131149-0.988897705762865i

◆ Equals()

override bool dsp.Complex.Equals ( object  obj)

◆ GetHashCode()

override int dsp.Complex.GetHashCode ( )

◆ isInfinity()

bool dsp.Complex.isInfinity ( )

Check if a complex number has infinite value

Returns
Returns true if real or imaginary part of the complex number evaluates to positive or negative infinity.


Example

Complex c = new Complex(25.5, double.NegativeInfinity);
Console.WriteLine(c.isInfinity());
True

◆ isNaN()

bool dsp.Complex.isNaN ( )

Check if a complex number has a value that is not a number

Returns
Returns true if real or imaginary part of the complex number evaluates to a value that is not a number


Example

Complex c = new Complex(25.5, double.NaN);
Console.WriteLine(c.isNaN());
True

◆ Ln()

static Complex dsp.Complex.Ln ( Complex  c)
static

Returns the natural (base e) logarithm of a complex number

Parameters
ccomplex number
Returns
$C=\ln(c)$

Example

Complex c = new Complex(-2, -1.5);
c = Complex.Ln(c);
Console.WriteLine(c);
0.916290731874155-2.49809154479651i

◆ Log() [1/2]

static Complex dsp.Complex.Log ( Complex  c,
double  a 
)
static

Returns the logarithm of a complex number on the specified real base

Parameters
ccomplex number
alogarithmic base (real number)
Returns
$C=\log_{a}(c)$

Example

Complex c = new Complex(-2, -1.5);
c = Complex.Log(c, 2);
Console.WriteLine(c);
1.32192809488736-3.60398428336457i

◆ Log() [2/2]

static Complex dsp.Complex.Log ( Complex  c,
Complex  a 
)
static

Returns the logarithm of a complex number

Parameters
ccomplex number
alogarithmic base (real number)
Returns
$C=\log_{a}(c)$

Example

Complex c = new Complex(2, -1.5);
c = Complex.Log(c, new Complex(4,2));
Console.WriteLine(c);
0.436889006331612-0.564845970680781i

◆ Log10()

static Complex dsp.Complex.Log10 ( Complex  c)
static

Returns the base 10 logarithm of a complex number

Parameters
ccomplex number
Returns
$C=\log_{10}(c)$

Example

Complex c = new Complex(-2, -1.5);
c = Complex.Log10(c);
Console.WriteLine(c);
0.397940008672038-1.08490737319429i

◆ Magnitude()

double dsp.Complex.Magnitude ( )

Returns the magnitude (abs) of a complex number

Returns
$|c|=\sqrt{\Re^2+\Im^2}$

Example

Complex c = new Complex(25.5, 42);
Console.WriteLine(c.Magnitude());
49.1350180624776

◆ operator Complex()

static implicit dsp.Complex.operator Complex ( double  value)
static

Implicit operator to assign the specified real value with zero imaginary part

Parameters
valuereal value

Example

Complex c = 3;
Console.WriteLine(c);
3+0i

◆ operator!=()

static bool dsp.Complex.operator!= ( Complex  A,
Complex  B 
)
static

Inequality check of two complex numbers

Parameters
Acomplex number
Bcomplex number
Returns
$true \iff A \ne B $

Example

Complex c1 = new Complex(-5.6, 4.7);
Complex c2 = new Complex(5.6, 4.7);
Console.WriteLine(c1 != c2);
True

◆ operator*()

static Complex dsp.Complex.operator* ( Complex  A,
Complex  B 
)
static

Multiplies two complex numbers

Parameters
Acomplex number
Bcomplex number


Returns
$C=A \times B$


Example

Complex c1 = new Complex(21.522, 1.545);
Complex c2 = new Complex(2.421, 324.23);
Complex c3 = c1 * c2;
Console.WriteLine(c3);
-448.830588+6981.818505i

◆ operator+()

static Complex dsp.Complex.operator+ ( Complex  A,
Complex  B 
)
static

Adds two complex numbers

Parameters
Acomplex number
Bcomplex number


Returns
$C=A+B$


Example

Complex c1 = new Complex(21.522, 1.545);
Complex c2 = new Complex(2.421, 324.23);
Complex c3 = c1 + c2;
Console.WriteLine(c3);
23.943+325.775i

◆ operator-() [1/2]

static Complex dsp.Complex.operator- ( Complex  A,
Complex  B 
)
static

Subtracts a complex number from another complex number

Parameters
Acomplex number
Bcomplex number


Returns
$C=A-B$


Example

Complex c1 = new Complex(21.522, 1.545);
Complex c2 = new Complex(2.421, 324.23);
Complex c3 = c1 - c2;
Console.WriteLine(c3);
19.101-322.685i

◆ operator-() [2/2]

static Complex dsp.Complex.operator- ( Complex  A)
static

Negates (opposite) a complex number

Reverses the sign of both the real and imaginary parts of a complex number.

Parameters
Acomplex number


Returns
$C=-1 \times A$


Example

Complex c1 = new Complex(-2, 4);
Console.WriteLine(c1);
2-4i

◆ operator/()

static Complex dsp.Complex.operator/ ( Complex  A,
Complex  B 
)
static

Divides a complex number by another complex number

Parameters
Acomplex number (dividend)
Bcomplex number (divisor)


Returns
$\displaystyle C=\frac{A}{B}$


Example

Complex c1 = new Complex(21.522, 1.545);
Complex c2 = new Complex(2.421, 324.23);
Complex c3 = c1 / c2;
Console.WriteLine(c3);
0.00526048789834316-0.0663395255182991i

◆ operator==()

static bool dsp.Complex.operator== ( Complex  A,
Complex  B 
)
static

Equality check of two complex numbers

Parameters
Acomplex number
Bcomplex number
Returns
$true \iff A=B $

Example

Complex c1 = new Complex(-5.6, 4.7);
Complex c2 = new Complex(5.6, 4.7);
Console.WriteLine(c1 == c2);
False

◆ Phase()

double dsp.Complex.Phase ( )

Returns the phase of a complex number in radians

Returns
$\displaystyle \Theta=\arctan\left(\frac{\Re}{\Im}\right), -\pi\leq\theta\leq\pi$

Example

Complex c = new Complex(25.5, 42);
Console.WriteLine(c.Phase());
1.0251412722679

◆ PolarToRec()

static Complex dsp.Complex.PolarToRec ( double  magnitude,
double  phase 
)
static

Polar-to-rectangular conversion

Creates a complex number from polar coordinates

Parameters
magnitudemagnitude of the complex number
phasephase of the complex number in radians
Returns
$C=\Re+\Im \\ \Re=M\cos(\theta) , \Im=M\sin(\theta)$

Example

Complex c = Complex.PolarToRec(15, 0.7854);
Console.WriteLine(c);
10.6065822376685+10.6066211978921i

◆ Pow()

static Complex dsp.Complex.Pow ( Complex  c,
double  a 
)
static

Returns the complex number raised to the specified power

Parameters
ccomplex number
aexponent (real number)
Returns
$C=c^a$

Example

Complex c = new Complex(3, -1);
c = Complex.Pow(c);
Console.WriteLine(c);
8-6i

◆ Power()

double dsp.Complex.Power ( )

Returns the power (absolute square) of a complex number

Returns
$|c|^2={\Re^2+\Im^2}$

Example

Complex c = new Complex(25.5, 42);
Console.WriteLine(c.Power());
2414.25

◆ Reciprocal()

static Complex dsp.Complex.Reciprocal ( Complex  c)
static

Returns the inverse of a complex number

Parameters
ccomplex number
Returns
$C=c^{-1}$

Example

Complex c = new Complex(3, -1);
c = Complex.Reciprocal(c);
Console.WriteLine(c);
0.3+0.1i

◆ Round()

static Complex dsp.Complex.Round ( Complex  c,
int  decimals 
)
static

Rounds a complex number to the specified number of fractional digits

Rounding applies on both real and imaginary components of the complex number using an away from zero mode.

Parameters
ccomplex number
decimalsnumber of fractional digits


Example

Complex c = new Complex(-1, 1);
c = Complex.Pow(c, 2);
Console.WriteLine(c);
c = Complex.Round(c, 8);
Console.WriteLine(c);
-3.67381906146713E-16-2i
0-2i

◆ Sin()

static Complex dsp.Complex.Sin ( Complex  c)
static

Returns the sine of a complex number

Parameters
ccomplex number
Returns
$C=\sin(a+bi)=\sin(a)\cosh(b)+i\cos(a)\sinh(b)$

Example

Complex c = new Complex(1, -1);
c = Complex.Sin(c);
Console.WriteLine(c);
1.29845758141598-0.634963914784736i

◆ Sinh()

static Complex dsp.Complex.Sinh ( Complex  c)
static

Returns the hyperbolic sine of a complex number

Parameters
ccomplex number
Returns
$\displaystyle C=\sinh(a+bi)=\sinh(a)\cos(b)+i\cosh(a)\sin(b)$

Example

Complex c = new Complex(1, -1);
c = Complex.Sinh(c);
Console.WriteLine(c);
0.634963914784736-1.29845758141598i

◆ Sqrt()

static Complex dsp.Complex.Sqrt ( Complex  c)
static

Returns the square root of a complex number

Parameters
ccomplex number
Returns
$C=\sqrt{c}$

Example

Complex c = new Complex(2, -1);
c = Complex.Sqrt(c);
Console.WriteLine(c);
1.45534669022535-0.343560749722512i

◆ Tan()

static Complex dsp.Complex.Tan ( Complex  c)
static

Returns the tangent of a complex number

Parameters
ccomplex number
Returns
$\displaystyle C=\tan(c)=\frac{\sin(c)}{\cos(c)}$

Example

Complex c = new Complex(1, -1);
c = Complex.Tan(c);
Console.WriteLine(c);
0.271752585319512-1.08392332733869i

◆ Tanh()

static Complex dsp.Complex.Tanh ( Complex  c)
static

Returns the hyperbolic tangent of a complex number

Parameters
ccomplex number
Returns
$\displaystyle C=\tanh(c)=\frac{\sinh(c)}{\cosh(c)}$

Example

Complex c = new Complex(1, -1);
c = Complex.Tanh(c);
Console.WriteLine(c);
1.08392332733869-0.271752585319512i

◆ ToString()

override string dsp.Complex.ToString ( )

Converts the value of a complex number to its equivalent string representation in Cartesian form

Example

Complex c = new Complex(3, 1);
Console.WriteLine(c);;
3+1i

Property Documentation

◆ Img

double dsp.Complex.Img
getset

Gets or sets the imaginary component of the complex number

Returns
$\Im$

Example

Complex c1 = new Complex(2.534, -4.895);
Console.WriteLine(c1.Img);
c1.Img = 10;
Console.WriteLine(c1.Img);
-4.895
10

◆ Real

double dsp.Complex.Real
getset

Gets or sets the real component of the complex number

Returns
$\Re$

Example

Complex c1 = new Complex(2.534, -4.895);
Console.WriteLine(c1.Real);
c1.Real = 10;
Console.WriteLine(c1.Real);
2.534
10