Classes are provided for solving quadratic, cubic, and quartic equations as well as general polynomials. There is a standard nomenclature: classes which handle polynomials with real coefficients and real roots end with the suffix _real
(o2scl::quadratic_real, o2scl::cubic_real and o2scl::quartic_real), classes which handle real coefficients and complex roots end with the suffix _real_coeff
(o2scl::quadratic_real_coeff, o2scl::cubic_real_coeff, o2scl::quartic_real_coeff, and o2scl::poly_real_coeff), and classes which handle complex polynomials with complex coefficients end with the suffix _complex
(o2scl::quadratic_complex, o2scl::cubic_complex, o2scl::quartic_complex, and o2scl::poly_complex). As a reminder, complex roots may not occur in conjugate pairs if the coefficients are not real. Most of these routines will return an error if the leading coefficient is zero.
In the public interfaces to the polynomial solvers, the complex type std::complex<double>
is used.
For quadratics, o2scl::quadratic_real_coeff_gsl is the best if the coefficients are real, while if the coefficients are complex, use o2scl::quadratic_complex_std. For cubics with real coefficients, o2scl::cubic_real_coeff_cern is the best, while if the coefficients are complex, use o2scl::cubic_complex_std.
For a quartic polynomial with real coefficients, o2scl::quartic_real_coeff_cern is the best, unless the coefficients of odd powers happen to be small, in which case, o2scl::quartic_real_gsl2 tends to work better. For quartics, generic polynomial solvers such as o2scl::poly_real_coeff_gsl can provide more accurate (but slower) results. If the coefficients are complex, then you can use o2scl::quartic_complex_simple.
This example shows how to find the roots of the second-, third-, fourth-, and fifth-order Chebyshev polynomials
For the Chebyshev polynomial of order , the roots are given by
for These roots are used in o2scl::cheb_approx to approximate functions using Chebyshev polynomials .
Documentation generated with Doxygen. Provided under the
GNU Free Documentation License (see License Information).