Example: Roots of a Quadratic Equation
The two roots of the quadratic equation are computed using the formula
using System;
using Imsl.Math;
public class ComplexEx1
{
public static void Main(String[] args)
{
Complex a = new Complex(2.0, 3.0);
double b = 4.0;
Complex c = new Complex(1.0, -2.0);
Complex disc = Complex.Sqrt(b*b - 4.0*a*c);
Complex root1 = (-b + disc) / (2.0*a);
Complex root2 = (-b - disc) / (2.0*a);
Console.Out.WriteLine("Root1 = " + root1);
Console.Out.WriteLine("Root2 = " + root2);
}
}
Output
Root1 = 0.19555270402037395+0.71433567154613054i
Root2 = -0.81093731940498925+0.20874125153079251i
Link to C# source.