XLPack 6.1
Excel VBA Numerical Library Reference Manual
Loading...
Searching...
No Matches

◆ Cpqr79()

Sub Cpqr79 ( N As  Long,
A() As  Complex,
Z() As  Complex,
Info As  Long 
)

Roots of a polynomial (complex coefficients) (by computing the eigenvalues of the companion matrix)

Purpose
This routine computes all roots of a polynomial p(z) with complex coefficients by computing the eigenvalues of the companion matrix.
p(z) = a0*z^n + a1*z^(n-1) + ... + an
Parameters
[in]NDegree of polynomial. (N >= 1)
[in]A()Array A(LA - 1) (LA >= N + 1)
Complex 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^3 + (-19-14i)*x^2 + (67+191i)*x + 116-612i = 0
The exact solutions are 8 + 4i, 4 + 9i and 7 + i.
Sub Ex_Cpqr79()
Const N As Long = 3
Dim A(N) As Complex, Z(N - 1) As Complex
Dim Info As Long, I As Long
A(0) = Cmplx(1): A(1) = Cmplx(-19, -14)
A(2) = Cmplx(67, 191): A(3) = Cmplx(116, -612)
Call Cpqr79(N, A(), Z(), Info)
For I = 0 To N - 1
Debug.Print Creal(Z(I)), Cimag(Z(I))
Next
Debug.Print "Info =", Info
End Sub
Example Results
4 9.00000000000001
7.99999999999999 3.99999999999998
7.00000000000001 1.00000000000001
Info = 0