NMath User's Guide

TOC | Previous | Next | Index

3.2 Value Operations on Complex Numbers (.NET, C#, CSharp, VB, Visual Basic, F#)

Both FloatComplex and DoubleComplex have public instance variables Real and Imag that you can use to access and modify the real and imaginary parts of a complex number. For instance:

Code Example – C# complex numbers

var c1 = new DoubleComplex( 1.0 );
var c2 = new DoubleComplex( 2.13, 5.6 );
c1.Imag = c2.Imag;
c1.Real = -7.77;

Code Example – VB complex numbers

Dim C1 As New DoubleComplex(1.0)
Dim C2 As New DoubleComplex(2.13, 5.6)
C1.Imag = C2.Imag
C1.Real = -7.77

You can also use the static functions Real() and Imag() on class NMathFunctions to return the real and imaginary parts of a complex number:

Code Example – C# complex numbers

var c = new DoubleComplex( 2.13, 5.6 );
double d1 = c.Real();
double d2 = NMathFunctions.Real( c );   // d2 == d1

Code Example – VB complex numbers

Dim C As New DoubleComplex(2.13, 5.6)
Dim D1 = C.Real
Dim D2 = NMathFunctions.Real(C)   ' d2 == d1

Top

Top