# NMath User's Guide

3.5 Functions of Complex Numbers (.NET, C#, CSharp, VB, Visual Basic, F#)

NMath provides a variety of functions that take complex numbers as arguments.

Conjugate, Norm, and Argument

NMath provides static functions on FloatComplex and DoubleComplex for common complex number functions:

The static Conj() function returns the conjugate of a complex number. The conjugate of a complex number a + bi is defined as ­- b­i.

The static Norm() method returns the norm (or modulus) of a complex number, defined as the square root of the sum of the squares of the real and imaginary parts.

The static Arg() method returns the argument of a complex number, defined as the directed phase angle in polar coordinates.

For instance:

Code Example – C# complex numbers

```var c = new FloatComplex( -8.2, 3.4 );
```
```FloatComplex conj = FloatComplex.Conj( c );
```
```float norm = FloatComplex.Norm( c );
```
```float arg = FloatComplex.Arg( c );
```

Code Example – VB complex numbers

```Dim C As New FloatComplex(-8.2, 3.4)
```
```Dim Conj = FloatComplex.Conj(C)
```
```Dim Norm = FloatComplex.Norm(C)
```
```Dim Arg = FloatComplex.Arg(C)
```

Trigonometric Functions

NMath extends standard trigonometric functions Sin(), Cos(), Sinh(), Cosh(), Tan(), and Tanh() to take complex number arguments. Class NMathFunctions provides these functions as static methods; all take a single complex number as an argument and return a complex number as a result:

Code Example – C# complex numbers

```var c = new DoubleComplex( 1.0, -3.9 );
```
```DoubleComplex sin = NMathFunctions.Sin( c );
```
```DoubleComplex cos = NMathFunctions.Cos( c );
```

Code Example – VB complex numbers

```Dim C As New DoubleComplex(1.0, -3.9)
```
```Dim Sin = NMathFunctions.Sin(C)
```
```Dim Cos = NMathFunctions.Cos(C)
```

Transcendental Functions

NMath extends standard transcendental functions Exp() and Log() to take complex arguments. Class NMathFunctions provides these functions as static methods. For example:

Code Example – C# complex numbers

```var c = new FloatComplex( -8.11, 3.04 );
```
```FloatComplex exp = NMathFunctions.Exp( c );
```
```FloatComplex log = NMathFunctions.Log( c );
```

Code Example – VB complex numbers

```Dim C As New FloatComplex(-8.11, 3.04)
```
```Dim Exp = NMathFunctions.Exp(C)
```
```Dim Log = NMathFunctions.Log(C)
```

Class NMathFunctions also provides several static overloads of the exponential function Pow(). Versions exist to:

raise a complex number to an integer exponent

raise a complex number to a real exponent

raise a complex number to a complex exponent

raise a real value to a complex exponent

All return a complex number. For instance:

Code Example – C# complex numbers

```var c1 = new DoubleComplex( 12.932, -4.0 );
```
```DoubleComplex c2 = NMathFunctions.Pow( c1, 3 );
```
```DoubleComplex c3 = NMathFunctions.Pow( c1, 1.12 );
```
```DoubleComplex c4 = NMathFunctions.Pow( c1, c3 );
```
```DoubleComplex c5 = NMathFunctions.Pow( 5.2, c1 );
```

Code Example – VB complex numbers

```Dim C1 As New DoubleComplex(12.932, -4.0)
```
```Dim C2 = NMathFunctions.Pow(C1, 3)
```
```Dim C3 = NMathFunctions.Pow(C1, 1.12)
```
```Dim C4 = NMathFunctions.Pow(C1, C3)
```
```Dim C5 = NMathFunctions.Pow(5.2, C1)
```

Absolute Value and Square Root

The static Abs() function on class NMathFunctions returns the absolute value of a complex number, which is simply equal to the norm:

Code Example – C# complex numbers

```var c = new DoubleComplex( 7.99, 0.3 );
```
```double abs = NMathFunctions.Abs( c );
```

Code Example – VB complex numbers

```Dim C As New DoubleComplex(7.99, 0.3)
```
```Dim Abs = NMathFunctions.Abs(C)
```

NMath also extends the standard Sqrt() function to take a complex argument, again as a static method on class NMathFunctions. For example:

Code Example – C# complex numbers

```var c = new FloatComplex( -8.11, 3.04 );
```
```FloatComplex sqrt = NMathFunctions.Sqrt( c );
```

Code Example – VB complex numbers

```Dim C As New FloatComplex(-8.11, 3.04)
```
```Dim Sqrt = NMathFunctions.Sqrt(C)

```

Top

Top