Roots of a polynomial (real coefficients) (by computing the eigenvalues of the companion matrix)
Purpose
This routine computes all roots of a polynomial p(z) with real coefficients by computing the eigenvalues of the companion matrix.
p(z) = a0*z^n + a1*z^(n-1) + ... + an
Parameters
[in]
N
Degree of polynomial. (N >= 1)
[in]
A()
Array A(LA - 1) (LA >= N + 1)
Real coefficient vector of p(z) (a0 to an).
[out]
Z()
Array Z(LZ - 1) (LZ >= N)
The obtained zeros.
[out]
Info
= 0: Successful exit.
= -1: The argument N had an illegal value. (N <= 0)
= -2: The argument A() is invalid.
= -3: The argument Z() is invalid.
= 1: Failed to converge within maximum number (30) of QR iterations on some eigenvalue of the companion matrix.
Reference
SLATEC
Example Program
Solve the following algebraic equation.
x^5 + 2*x^3 + 2*x^2 - 15*x + 10 = 0
The exact solutions are 1(double root), -2 and ±√5.
Sub Ex_Rpqr79()
Const N As Long = 5
Dim A(N) As Double, Z(N - 1) As Complex, S(N - 1) As Double