| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This chapter describes functions for evaluating and solving polynomials.
There are routines for finding real and complex roots of quadratic and
cubic equations using analytic methods. An iterative polynomial solver
is also available for finding the roots of general polynomials with real
coefficients (of any order). The functions are declared in the header
file gsl_poly.h.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This function evaluates the polynomial
using
Horner's method for stability. The function is inlined when possible.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The functions described here manipulate polynomials stored in Newton's divided-difference representation. The use of divided-differences is described in Abramowitz & Stegun sections 25.1.4 and 25.2.26.
This function computes a divided-difference representation of the interpolating polynomial for the points (xa, ya) stored in the arrays xa and ya of length size. On output the divided-differences of (xa,ya) are stored in the array dd, also of length size.
This function evaluates the polynomial stored in divided-difference form in the arrays dd and xa of length size at the point x.
This function converts the divided-difference representation of a polynomial to a Taylor expansion. The divided-difference representation is supplied in the arrays dd and xa of length size. On output the Taylor coefficients of the polynomial expanded about the point xp are stored in the array c also of length size. A workspace of length size must be provided in the array w.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This function finds the real roots of the quadratic equation,
The number of real roots (either zero, one or two) is returned, and
their locations are stored in x0 and x1. If no real roots
are found then x0 and x1 are not modified. If one real root
is found (i.e. if
) then it is stored in x0. When two
real roots are found they are stored in x0 and x1 in
ascending order. The case of coincident roots is not considered
special. For example
will have two roots, which happen
to have exactly equal values.
The number of roots found depends on the sign of the discriminant
. This will be subject to rounding and cancellation
errors when computed in double precision, and will also be subject to
errors if the coefficients of the polynomial are inexact. These errors
may cause a discrete change in the number of roots. However, for
polynomials with small integer coefficients the discriminant can always
be computed exactly.
This function finds the complex roots of the quadratic equation,
The number of complex roots is returned (either one or two) and the
locations of the roots are stored in z0 and z1. The roots
are returned in ascending order, sorted first by their real components
and then by their imaginary components. If only one real root is found
(i.e. if
) then it is stored in z0.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This function finds the real roots of the cubic equation,
with a leading coefficient of unity. The number of real roots (either
one or three) is returned, and their locations are stored in x0,
x1 and x2. If one real root is found then only x0 is
modified. When three real roots are found they are stored in x0,
x1 and x2 in ascending order. The case of coincident roots
is not considered special. For example, the equation
will have three roots with exactly equal values.
This function finds the complex roots of the cubic equation, The number of complex roots is returned (always three) and the locations of the roots are stored in z0, z1 and z2. The roots are returned in ascending order, sorted first by their real components and then by their imaginary components.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The roots of polynomial equations cannot be found analytically beyond the special cases of the quadratic, cubic and quartic equation. The algorithm described in this section uses an iterative method to find the approximate locations of roots of higher order polynomials.
This function allocates space for a gsl_poly_complex_workspace
struct and a workspace suitable for solving a polynomial with n
coefficients using the routine gsl_poly_complex_solve.
The function returns a pointer to the newly allocated
gsl_poly_complex_workspace if no errors were detected, and a null
pointer in the case of error.
This function frees all the memory associated with the workspace w.
This function computes the roots of the general polynomial
using
balanced-QR reduction of the companion matrix. The parameter n
specifies the length of the coefficient array. The coefficient of the
highest order term must be non-zero. The function requires a workspace
w of the appropriate size. The
roots are returned in
the packed complex array z of length
, alternating
real and imaginary parts.
The function returns GSL_SUCCESS if all the roots are found. If
the QR reduction does not converge, the error handler is invoked with
an error code of GSL_EFAILED. Note that due to finite precision,
roots of higher multiplicity are returned as a cluster of simple roots
with reduced accuracy. The solution of polynomials with higher-order
roots requires specialized algorithms that take the multiplicity
structure into account (see e.g. Z. Zeng, Algorithm 835, ACM
Transactions on Mathematical Software, Volume 30, Issue 2 (2004), pp
218–236).
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
To demonstrate the use of the general polynomial solver we will take the
polynomial
which has the following roots,
The following program will find these roots.
|
The output of the program is,
$ ./a.outz0 = -0.809016994374947451 +0.587785252292473137 z1 = -0.809016994374947451 -0.587785252292473137 z2 = +0.309016994374947451 +0.951056516295153642 z3 = +0.309016994374947451 -0.951056516295153642 z4 = +1.000000000000000000 +0.000000000000000000 |
which agrees with the analytic result,
.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The balanced-QR method and its error analysis are described in the following papers,
The formulas for divided differences are given in Abramowitz and Stegun,
| [ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated by Autobuild on September, 26 2007 using texi2html 1.78.