Function.quadratic_solve()
6. API Reference: `Function.quadratic_solve()` Method
For the special case of degree-2 polynomials (quadratics), the Function class provides a direct, analytical solver method using the quadratic formula. This is much faster and more precise than the genetic algorithm for this specific case.
The method returns a sorted list containing two numbers (floats or complex). If the quadratic has no real roots, it will return **complex roots** (e.g., `(-1+2j)`).from polysolve import Function# Case 1: Real Roots# f(x) = x² - x - 6f_quad = Function(2)f_quad.set_coeffs([1, -1, -6])print(f_quad.quadratic_solve()) # Output: [-2.0, 3.0]# Case 2: Complex Roots# f(x) = x² + 1 (roots are +j and -j)f_complex = Function(2)f_complex.set_coeffs([1, 0, 1])print(f_complex.quadratic_solve()) # Output: [(-0-1j), 1j]
