quadratic_solve() API
6. API Reference: `quadratic_solve()`
For the special case of degree-2 polynomials (quadratics), PolySolve provides a direct, analytical solver using the quadratic formula. This is much faster and more precise than the genetic algorithm for this specific case.
from polysolve import Function, quadratic_solve
# f(x) = x² - x - 6
f_quad = Function(2)
f_quad.set_coeffs([1, -1, -6])
# Use the analytical solver
exact_roots = quadratic_solve(f_quad)
print(exact_roots) # Output: [3.0, -2.0]
The function returns a list containing two floats. If the quadratic has no real roots (i.e., the discriminant is negative), it will return None
.