Complex numbers are not new to numeral system. A complex number contains one real part and another imaginary part. We can easily implement such a Type, but with .NET 4.0
System.Numerics.dll contains a new
Type (struct) called
Complex which deals with
Complex numbers .
You can represent a number in Complex form very easily using Complex type.
Lets see how :
Complex c = new Complex(4.4, 3.1); Console.WriteLine(c);
You can even specify like this :
Complex c = 35.302; Console.WriteLine(c);
Or like this :
Complex c = (Complex)35.302m; Console.WriteLine(c);
So everything is taken care automatically. You can also use
FromPolarCoordinates to take a complex number from its polar co-ordinates.
Complex c = Complex.FromPolarCoordinates(39.454834, 2.548454); Console.WriteLine(c);
You can get each component of a Complex number using properties associated with it.
Real : Represents the Real part of the Number.
Imaginary : Represents the Imaginary part of the number.
Magintude : Gets the absolute value of the Complex number
Phase : Gets the phase of the complex number.
The complex number also exposes some of the important methods :
Sqrt (Square Root) etc.
For more information about Complex numbers please refer ComplexNumber
Hope you like this post.