Using Complex Numbers in .NET 4.0

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 :

Conjugate
Log
Reciprocal
Sqrt (Square Root) etc.

For more information about Complex numbers please refer ComplexNumber
Hope you like this post.
Happy Coding.

Abhishek Sur

Abhishek Sur is a Microsoft MVP since year 2011. He is an architect in the .NET platform. He has profound theoretical insight and years of hands on experience in different .NET products and languages. He leads the Microsoft User Group in Kolkata named KolkataGeeks, and regularly organizes events and seminars in various places for spreading .NET awareness. He is associated with the Microsoft Insider list on WPF and C#, and is in constant touch with product group teams. He blogs at http://www.abhisheksur.com His Book : Visual Studio 2012 and .NET 4.5 Expert Development Cookbook. Follow Abhishek at Twitter : @abhi2434

3 Comments to “Using Complex Numbers in .NET 4.0”

  1. Has any one else heard about the possibility of xbox producing a portable version? I hear that it’s to go after Apple, psp’s and the DS. Microsoft is trying to completely kill all the competition and I love it. Has any one else heard anything about this news. I am a Video Game Tester and this has been kept in the dark from me. So, any informaton would be helpful. I would pay to get my hands on one of these consoles!

  2. Is anybody else as astounded as I am about the news that came from the E3? Controlled voicing, Bing search engine, and the new Kinect games! I hear you can even control any movies and youtube by just your voice! UFC is also joining up with Microsoft. They have now taken a huge lead in the gaming industry! If anyone knows where I can be a Video Game Tester for these new games, please post on here. I am already testing several, but have been unable to get my hands on the kinect games. So, what else have you guys heard about the new kinect?

  3. Is anybody else as astounded as I am about the news that came from the E3? Voice controls, Bing search engine, and the new Kinect games! I hear you can even control all movies and youtube by just your voice! UFC is also partnering up with Microsoft. They have now taken a humongous lead in the gaming industry! If anyone knows where I can be a Video Game Tester for these new games, give me a hollar. I am already testing several, but have been unable to get my hands on the kinect games. So, what else have you guys heard about the new kinect?

Comments are closed.