.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32 .\" .\" Standard preamble: .\" ======================================================================== .de Sh \" Subsection heading .br .if t .Sp .ne 5 .PP \fB\\$1\fR .PP .. .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. | will give a .\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to .\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C' .\" expand to `' in nroff, nothing in troff, for use with C<>. .tr \(*W-|\(bv\*(Tr .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' 'br\} .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .\" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .hy 0 .if n .na .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Math::Polynomial::Solve 3" .TH Math::Polynomial::Solve 3 "2007-02-23" "perl v5.8.8" "User Contributed Perl Documentation" .SH "NAME" Math::Polynomial::Solve \- Find the roots of polynomial equations. .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& use Math::Complex; # The roots may be complex numbers. \& use Math::Polynomial::Solve qw(poly_roots); .Ve .PP .Vb 1 \& my @x = poly_roots(@coefficients); .Ve .PP or .PP .Vb 2 \& use Math::Complex; # The roots may be complex numbers. \& use Math::Polynomial::Solve qw(poly_roots get_hessenberg set_hessenberg); .Ve .PP .Vb 5 \& # \& # Force the use of the matrix method. \& # \& set_hessenberg(1); \& my @x = poly_roots(@coefficients); .Ve .PP or .PP .Vb 3 \& use Math::Complex; # The roots may be complex numbers. \& use Math::Polynomial::Solve \& qw(linear_roots quadratic_roots cubic_roots quartic_roots); .Ve .PP .Vb 2 \& # Find the roots of ax + b \& my @x1 = linear_roots($a, $b); .Ve .PP .Vb 2 \& # Find the roots of ax**2 + bx +c \& my @x2 = quadratic_roots($a, $b, $c); .Ve .PP .Vb 2 \& # Find the roots of ax**3 + bx**2 +cx + d \& my @x3 = cubic_roots($a, $b, $c, $d); .Ve .PP .Vb 2 \& # Find the roots of ax**4 + bx**3 +cx**2 + dx + e \& my @x4 = quartic_roots($a, $b, $c, $d, $e); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This package supplies a set of functions that find the roots of polynomials. Polynomials up to the quartic may be solved directly by numerical formulae. Polynomials of fifth and higher powers will be solved by an iterative method, as there are no general solutions for fifth and higher powers. .PP The linear, quadratic, cubic, and quartic *\fI_roots()\fR functions all expect to have a non-zero value for the \f(CW$a\fR term. .PP If the constant term is zero then the first value returned in the list of answers will always be zero, for all functions. .Sh "\fIset_hessenberg()\fP" .IX Subsection "set_hessenberg()" Sets or removes the condition that forces the use of the Hessenberg matrix regardless of the polynomial's degree. A non-zero argument forces the use of the matrix method, a zero removes it. .Sh "\fIget_hessenberg()\fP" .IX Subsection "get_hessenberg()" Returns 1 or 0 depending upon whether the Hessenberg matrix method is always in use or not. .Sh "\fIpoly_roots()\fP" .IX Subsection "poly_roots()" A generic function that may call one of the other root-finding functions, or a polynomial solving method using a Hessenberg matrix, depending on the degree of the polynomial. You may force it to use the matrix method regardless of the degree of the polynomial by calling \f(CWset_hessenberg(1)\fR. Otherwise it will use the specialized root functions for polynomials of degree 1 to 4. .PP Unlike the other root-finding functions, it will check for coefficients of zero for the highest power, and 'step down' the degree of the polynomial to the appropriate case. Additionally, it will check for coefficients of zero for the lowest power terms, and add zeros to its root list before calling one of the root-finding functions. Thus it is possible to solve a polynomial of degree higher than 4 without using the matrix method, as long as it meets these rather specialized conditions. .Sh "\fIlinear_roots()\fP" .IX Subsection "linear_roots()" Here for completeness's sake more than anything else. Returns the solution for .PP .Vb 1 \& ax + b = 0 .Ve .PP by returning \f(CW\*(C`\-b/a\*(C'\fR. This may be in either a scalar or an array context. .Sh "\fIquadratic_roots()\fP" .IX Subsection "quadratic_roots()" Gives the roots of the quadratic equation .PP .Vb 1 \& ax**2 + bx + c = 0 .Ve .PP using the well-known quadratic formula. Returns a two-element list. .Sh "\fIcubic_roots()\fP" .IX Subsection "cubic_roots()" Gives the roots of the cubic equation .PP .Vb 1 \& ax**3 + bx**2 + cx + d = 0 .Ve .PP by the method described by R. W. D. Nickalls (see the Acknowledgments section below). Returns a three-element list. The first element will always be real. The next two values will either be both real or both complex numbers. .Sh "\fIquartic_roots()\fP" .IX Subsection "quartic_roots()" Gives the roots of the quartic equation .PP .Vb 1 \& ax**4 + bx**3 + cx**2 + dx + e = 0 .Ve .PP using Ferrari's method (see the Acknowledgments section below). Returns a four-element list. The first two elements will be either both real or both complex. The next two elements will also be alike in type. .Sh "\s-1EXPORT\s0" .IX Subsection "EXPORT" There are no default exports. The functions may be named in an export list. .SH "Acknowledgments" .IX Header "Acknowledgments" .Sh "The cubic" .IX Subsection "The cubic" The cubic is solved by the method described by R. W. D. Nickalls, \*(L"A New Approach to solving the cubic: Cardan's solution revealed,\*(R" The Mathematical Gazette, 77, 354\-359, 1993. This article is available on several different web sites, including and . There is also a nice discussion of his paper at . .PP Dr. Nickalls was kind enough to send me his article, with notes and revisions, and directed me to a Matlab script that was based on that article, written by Herman Bruyninckx, of the Dept. Mechanical Eng., Div. \s-1PMA\s0, Katholieke Universiteit Leuven, Belgium. This function is an almost direct translation of that script, and I owe Herman Bruyninckx for creating it in the first place. .PP Dick Nickalls, dicknickalls@compuserve.com .PP Herman Bruyninckx, Herman.Bruyninckx@mech.kuleuven.ac.be, has web page at . His matlab cubic solver is at . .PP Andy Stein has written a version of cubic.m that will work with vectors. It is included with this package in the eg directory. .Sh "The quartic" .IX Subsection "The quartic" The method for quartic solution is Ferrari's, as described in the web page Karl's Calculus Tutor at . I also made use of some short cuts mentioned in web page Ask Dr. Math \s-1FAQ\s0, at . .Sh "Quintic and higher." .IX Subsection "Quintic and higher." Back when this module could only solve polynomials of degrees 1 through 4, Matz Kindahl, the author of Math::Polynomial, suggested the \fIpoly_roots()\fR function. Later on, Nick Ing\-Simmons, who was working on a perl binding to the \s-1GNU\s0 Scientific Library, sent a perl translation of Hiroshi Murakami's Fortran implementation of the \s-1QR\s0 Hessenberg algorithm, and it fit very well into the \fIpoly_roots()\fR function. Quintics and higher degree polynomials can now be solved, albeit through numeric analysis methods. .PP Hiroshi Murakami's Fortran routines were at , but do not seem to be available from that source anymore. .PP He referenced the following articles: .PP R. S. Martin, G. Peters and J. H. Wilkinson, \*(L"The \s-1QR\s0 Algorithm for Real Hessenberg Matrices\*(R", Numer. Math. 14, 219\-231(1970). .PP B. N. Parlett and C. Reinsch, \*(L"Balancing a Matrix for Calculation of Eigenvalues and Eigenvectors\*(R", Numer. Math. 13, 293\-304(1969). .PP Alan Edelman and H. Murakami, \*(L"Polynomial Roots from Companion Matrix Eigenvalues\*(R", Math. Comp., v64,#210, pp.763\-776(1995). .PP For starting out, you may want to read .PP Numerical Recipes in C, by William Press, Brian P. Flannery, Saul A. Teukolsky, and William T. Vetterling, Cambridge University Press. .SH "SEE ALSO" .IX Header "SEE ALSO" Forsythe, George E., Michael A. Malcolm, and Cleve B. Moler (1977), Computer Methods for Mathematical Computations, Prentice\-Hall. .SH "AUTHOR" .IX Header "AUTHOR" John M. Gamble may be found at \fBjgamble@ripco.com\fR