⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 poly.texi

📁 开放gsl矩阵运算
💻 TEXI
字号:
@cindex polynomials, roots of This chapter describes functions for evaluating and solving polynomials.There are routines for finding real and complex roots of quadratic andcubic equations using analytic methods.  An iterative polynomial solveris also available for finding the roots of general polynomials with realcoefficients (of any order).  The functions are declared in the headerfile @code{gsl_poly.h}.@menu* Polynomial evaluation::       * Quadratic equations::         * Cubic equations::             * General polynomial equations::  * Roots of Polynomials Examples::  * Roots of Polynomials References and Further Reading::  @end menu@node Polynomial evaluation@section Polynomial evaluation@cindex polynomial evaluation@cindex evaluation of polynomials@deftypefun double gsl_poly_eval (const double c[], const int @var{len}, const double @var{x})This function evaluates the polynomial @c{$c[0] + c[1] x + c[2] x^2 + \dots + c[len-1] x^{len-1}$}@math{c[0] + c[1] x + c[2] x^2 + \dots + c[len-1] x^@{len-1@}} usingHorner's method for stability.  The function is inlined when possible.@end deftypefun@node  Quadratic equations@section Quadratic equations@cindex quadratic equation, solving@deftypefun int gsl_poly_solve_quadratic (double @var{a}, double @var{b}, double @var{c}, double *@var{x0}, double *@var{x1})This function finds the real roots of the quadratic equation,@tex\beforedisplay$$a x^2 + b x + c = 0$$\afterdisplay@end tex@ifinfo@examplea x^2 + b x + c = 0@end example@end ifinfo@noindentThe number of real roots (either zero or two) is returned, and theirlocations are stored in @var{x0} and @var{x1}.  If no real roots arefound then @var{x0} and @var{x1} are not modified.  When two real rootsare found they are stored in @var{x0} and @var{x1} in ascendingorder.  The case of coincident roots is not considered special.  Forexample @math{(x-1)^2=0} will have two roots, which happen to haveexactly equal values.The number of roots found depends on the sign of the discriminant@math{b^2 - 4 a c}.  This will be subject to rounding and cancellationerrors when computed in double precision, and will also be subject toerrors if the coefficients of the polynomial are inexact.  These errorsmay cause a discrete change in the number of roots.  However, forpolynomials with small integer coefficients the discriminant can alwaysbe computed exactly.@end deftypefun@deftypefun int gsl_poly_complex_solve_quadratic (double @var{a}, double @var{b}, double @var{c}, gsl_complex *@var{z0}, gsl_complex *@var{z1})This function finds the complex roots of the quadratic equation,@tex\beforedisplay$$a z^2 + b z + c = 0$$\afterdisplay@end tex@ifinfo@examplea z^2 + b z + c = 0@end example@end ifinfo@noindentThe number of complex roots is returned (always two) and the locationsof the roots are stored in @var{z0} and @var{z1}.  The roots are returnedin ascending order, sorted first by their real components and then bytheir imaginary components.@end deftypefun@node Cubic equations@section Cubic equations@cindex cubic equation, solving@deftypefun int gsl_poly_solve_cubic (double @var{a}, double @var{b}, double @var{c}, double *@var{x0}, double *@var{x1}, double *@var{x2})This function finds the real roots of the cubic equation,@tex\beforedisplay$$x^3 + a x^2 + b x + c = 0$$\afterdisplay@end tex@ifinfo@examplex^3 + a x^2 + b x + c = 0@end example@end ifinfo@noindentwith a leading coefficient of unity.  The number of real roots (eitherone or three) is returned, and their locations are stored in @var{x0},@var{x1} and @var{x2}.  If one real root is found then only @var{x0} ismodified.  When three real roots are found they are stored in @var{x0},@var{x1} and @var{x2} in ascending order.  The case of coincident rootsis not considered special.  For example, the equation @math{(x-1)^3=0}will have three roots with exactly equal values.@end deftypefun@deftypefun int gsl_poly_complex_solve_cubic (double @var{a}, double @var{b}, double @var{c}, gsl_complex *@var{z0}, gsl_complex *@var{z1}, gsl_complex *@var{z2})This function finds the complex roots of the cubic equation,@tex\beforedisplay$$z^3 + a z^2 + b z + c = 0$$\afterdisplay@end tex@ifinfo@examplez^3 + a z^2 + b z + c = 0@end example@end ifinfo@noindentThe number of complex roots is returned (always three) and the locationsof the roots are stored in @var{z0}, @var{z1} and @var{z2}.  The rootsare returned in ascending order, sorted first by their real componentsand then by their imaginary components.@end deftypefun@node General polynomial equations@section General polynomial equations@cindex general polynomial equations, solvingThe roots of polynomial equations cannot be found analytically beyondthe special cases of the quadratic, cubic and quartic equation.  Thealgorithm described in this section uses an iterative method to find theapproximate locations of roots of higher order polynomials.@deftypefun {gsl_poly_complex_workspace *} gsl_poly_complex_workspace_alloc (size_t @var{n})This function allocates space for a @code{gsl_poly_complex_workspace}struct and a workspace suitable for solving a polynomial with @var{n}coefficients using the routine @code{gsl_poly_complex_solve}.The function returns a pointer to the newly allocated@code{gsl_poly_complex_workspace} if no errors were detected, and a nullpointer in the case of error.@end deftypefun@deftypefun void gsl_poly_complex_workspace_free (gsl_poly_complex_workspace * @var{w})This function frees all the memory associated with the workspace@var{w}.@end deftypefun@deftypefun int gsl_poly_complex_solve (const double * @var{a}, size_t @var{n}, gsl_poly_complex_workspace * @var{w}, gsl_complex_packed_ptr @var{z})This function computes the roots of the general polynomial @c{$P(x) = a_0 + a_1 x + a_2 x^2 + ... + a_{n-1} x^{n-1}$} @math{P(x) = a_0 + a_1 x + a_2 x^2 + ... + a_@{n-1@} x^@{n-1@}} using balanced-QR reduction of the companion matrix.  The parameter @var{n}specifies the length of the coefficient array.  The coefficient of thehighest order term must be non-zero.  The function requires a workspace@var{w} of the appropriate size.  The @math{n-1} roots are returned inthe packed complex array @var{z} of length @math{2(n-1)}, alternatingreal and imaginary parts.The function returns @code{GSL_SUCCESS} if all the roots are found and@code{GSL_EFAILED} if the QR reduction does not converge.@end deftypefun@node Roots of Polynomials Examples@section ExamplesTo demonstrate the use of the general polynomial solver we will take thepolynomial @math{P(x) = x^5 - 1} which has the following roots,@tex\beforedisplay$$1, e^{2\pi i /5}, e^{4\pi i /5}, e^{6\pi i /5}, e^{8\pi i /5}$$\afterdisplay@end tex@ifinfo@example1, e^@{2\pi i /5@}, e^@{4\pi i /5@}, e^@{6\pi i /5@}, e^@{8\pi i /5@}@end example@end ifinfo@noindentThe following program will find these roots.@example#include <stdio.h>#include <gsl/gsl_poly.h>intmain (void)@{  int i;  /* coefficient of P(x) =  -1 + x^5  */  double a[6] = @{ -1, 0, 0, 0, 0, 1 @};    double z[10];  gsl_poly_complex_workspace * w       = gsl_poly_complex_workspace_alloc (6);    gsl_poly_complex_solve (a, 6, w, z);  gsl_poly_complex_workspace_free (w);  for (i = 0; i < 5; i++)    @{      printf("z%d = %+.18f %+.18f\n",              i, z[2*i], z[2*i+1]);    @}  return 0;@}@end example@noindentThe output of the program is,@examplebash$ ./a.out z0 = -0.809016994374947451 +0.587785252292473137z1 = -0.809016994374947451 -0.587785252292473137z2 = +0.309016994374947451 +0.951056516295153642z3 = +0.309016994374947451 -0.951056516295153642z4 = +1.000000000000000000 +0.000000000000000000@end example@noindentwhich agrees with the analytic result, @math{z_n = \exp(2 \pi n i/5)}.@node Roots of Polynomials References and Further Reading@section References and Further Reading@noindentThe balanced-QR method and its error analysis is described in thefollowing papers.@itemize @asis@itemR.S. Martin, G. Peters and J.H. Wilkinson, ``The QR Algorithm for RealHessenberg Matrices'', @cite{Numerische Mathematik}, 14 (1970), 219--231.@itemB.N. Parlett and C. Reinsch, ``Balancing a Matrix for Calculation ofEigenvalues and Eigenvectors'', @cite{Numerische Mathematik}, 13 (1969),293--304.@itemA. Edelman and H. Murakami, ``Polynomial roots from companion matrixeigenvalues'', @cite{Mathematics of Computation}, Vol. 64 No. 210(1995), 763--776.@end itemize

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -