13,193,829 members (47,940 online)
alternative version

#### Stats

22.1K views
7 bookmarked
Posted 25 Oct 2010

# An introduction to Complex Struct of dotnet 4.0

, 27 Oct 2010
 Rate this:
This short article will show some of the benifits that the Complex Struct provides

## Introduction

The Complex struct which resides in System.Numerics assembly is use for representing complex numbers.

For using the Complex struct, we need to Add the System.Numerics assembly to our project

## Using the code

Let us see some examples as how it helps us

Example 1: Display the Real,Imaginary,Magnitude and Phase parts

```static void Main(string[] args)
{
Complex c1 = new Complex(12, 24);
Complex c2 = new Complex(21, 34);
string format1 = "Real,Imaginary,Magnitude,Phase part of first Complex is {0}, {1},{2},{3} respectively";
Console.WriteLine(format1, c1.Real, c1.Imaginary, c1.Magnitude, c1.Phase);
string format2 = "Real,Imaginary,Magnitude,Phase part of second Complex is {0}, {1},{2},{3} respectively";
Console.WriteLine(format2, c2.Real, c2.Imaginary, c1.Magnitude, c1.Phase);
}```

The output is

Example 2: Simple Addition of Complex Numbers

```static void Main(string[] args)
{
Complex c1 = new Complex(12, 24);
Complex c2 = new Complex(21, 34);
Complex result = c1 + c2;
Console.WriteLine("Addition of Complex numbers is {0}", result);
}
```

The result being

Addition can also be performed by using the Add method of Complex struct as shown below

```Complex.Add(c1, c2)
```

Likewise, we can do Complex.Subract,Complex.Multiply, Complex.Divide etc.

Example 3: Negation of Complex Number

Complex number negation can be perform by using the minus(-) sign before the complex number

`Console.WriteLine("</span />Negation of First Complex numbers is {0}"</span />, -c1);`

OR

`Complex.Negate(c1)`

Output

Example 4: Conjugate of Complex number

`Complex.Conjugate(c1)`

conjugates the first complex number

Example 5: Reciprocal of Complex number

`Complex.Reciprocal(c1))`

does reciprocate the first complex number.

Example 6: Exponential of Complex number

`Complex.Exp(c1)`

results into the exponential of the first complex number

Example 7: Trigonometric function of Complex number

`Complex.Sin(c1)`

yields the sin of the first Complex Number

`Complex.Cos(c1)`

yields the Cosin of the first Complex Number

`Complex.Tan(c1)`

yields the Tangent of the first Complex Number

Here is the output

Likewise, there are many other trigonometric functions

Example 8: Find the Log base 10 of Complex Number

`Complex.Log10(c1)`

gives the result.

Similarly other logarithmic functions are available.

## Conclusion:

In this article we have seen how the new Complex Struct of .Net Framework 4.0 has helped us in accomplishing complex number operations.

Comments on the topic are highly appreciated for the improvement of the topic.

## You may also be interested in...

 Pro

 First Prev Next
 My vote of 4 Rudra rafiq17-May-11 0:19 Rudra rafiq 17-May-11 0:19
 My vote of 1 Hiren Solanki10-Dec-10 2:57 Hiren Solanki 10-Dec-10 2:57
 My vote of 1 Batzen28-Oct-10 1:52 Batzen 28-Oct-10 1:52
 My vote of 1 SledgeHammer0127-Oct-10 7:25 SledgeHammer01 27-Oct-10 7:25
 My vote of 1 Argyle4Ever27-Oct-10 4:25 Argyle4Ever 27-Oct-10 4:25
 My vote of 1 JF201526-Oct-10 18:10 JF2015 26-Oct-10 18:10
 I haven't down-voted your article Henry Minute26-Oct-10 12:24 Henry Minute 26-Oct-10 12:24
 I have not voted at all but I was sorely tempted. Most of the content here can be found on MSDN and padding it out with needless images, such as the one of the Add Reference Dialog shames you. You have written some nice articles in the past, so I know that you can. If you want to demonstrate new features, an admirable aim, do something real. I haven't looked closely enough at the Complex Struct yet to know if it is feasible, but it strikes me that even using it for a Mandelbrot Set would be at least interesting, even though there are loads of examples out there. Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
 My vote of 2 Daniel Brännström26-Oct-10 9:41 Daniel Brännström 26-Oct-10 9:41
 My vote of 1 Selvin26-Oct-10 4:28 Selvin 26-Oct-10 4:28
 My vote of 1 `leppie`26-Oct-10 1:54 `leppie` 26-Oct-10 1:54
 Last Visit: 31-Dec-99 18:00     Last Update: 18-Oct-17 23:35 Refresh 1