![]() |
Languages »
C# »
General
Intermediate
A C# class for complex numbersBy hanzzoidImplementation of the most common functions of complex numbers. |
C#2.0, Windows, .NET2.0, Visual-Studio, Dev, QA, Design
|
||||||||||
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
Here you go: A simple but mathematically rigorous implementation of complex numbers in one small C# library. No problem in square rooting negative numbers anymore!
Either add reference to CompLib.dll to your project or directly use the class Complex.cs within your project.
Actual usage is intuitive:
Complex I = Complex.I; // imaginary unit
Complex a = new Complex(1, 3); // inits a = 1+3i
Complex a2 = 1 + 3 * I; // a equals a2
Complex z = Complex.Pow((Complex.Sin(1/(1+I))), 1/3);
One more thing: Complex logarithm is not a unique operation; the main value is computed as is common in the CAS world. E.g. the equation z^4 = -1 has four complex solution, but only one is returned when trying "z = Complex.Sqrt(Complex.Sqrt(-1));" (as does Maple, for instance). This is due to the computation of the exponentiation:
Pow(a,b) := Exp(b * Log(a)).
init complex number with format string such as "3+4i" using regex
replaced ^-operator with "public static Complex Pow", similar to Math.Pow
General
News
Question
Answer
Joke
Rant
Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+PgUp/PgDown to switch pages.
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 3 Jul 2007 Editor: |
Copyright 2007 by hanzzoid Everything else Copyright © CodeProject, 1999-2010 Web20 | Advertise on the Code Project |