public static IList <double> QuadraticDRootsPoMax(double a, double b, double c, double epsilon = Epsilon) { // If a is 0 the polynomial is linear. if (a is 0d) { return(LinearRootsTests.LinearRoots(b, c, epsilon)); } var d = a - (2d * b) + c; if (d != 0) { // The 4 is missing? var m1 = -Sqrt((b * b) - (a * c)); var m2 = -a + b; var v1 = -(m1 + m2) / d; var v2 = -(-m1 + m2) / d; return(new List <double> { v1, v2 }); } else if (b != c && d == 0d) { return(new List <double> { ((2d * b) - c) / (2d * (b - c)) }); } return(new List <double>()); }
public static IList <double> QuadraticEquation(double a, double b, double c, double epsilon = Epsilon) { // If a is 0 the polynomial is linear. if (a is 0d) { return(LinearRootsTests.LinearRoots(b, c, epsilon)); } return(new List <double> { (-b - Sqrt((b * b) - (4d * a * c))) / (2d * a), (-b + Sqrt((b * b) - (4d * a * c))) / (2d * a), }); }
public static IList <double> QuadraticRootsKevinLinDev(double a, double b, double c, double epsilon = Epsilon) { // If a is 0 the polynomial is linear. if (a is 0d) { return(LinearRootsTests.LinearRoots(b, c, epsilon)); } var b_ = b / a; var c_ = c / a; // Polynomial discriminant. var discriminant = (b_ * b_) - (4d * c_); if (Abs(discriminant) <= epsilon) { discriminant = 0d; } // ToDo: May need to switch from a hash set to a list for scan-beams. var results = new HashSet <double>(); if (discriminant > 0d) { // Complex or duplicate roots. var e = Sqrt(discriminant); results.Add(OneHalf * (-b_ + e)); results.Add(OneHalf * (-b_ - e)); } else if (discriminant == 0) { // There should actually be two roots with same value, but we will only return one. results.Add(OneHalf * -b_); } else if (discriminant < 0d) { // Complex or duplicate roots. var e = -Sqrt(-discriminant); results.Add(OneHalf * (-b_ + e)); results.Add(OneHalf * (-b_ - e)); } return(results.ToList()); }