|
|
◆ Cpqr79()
| Sub Cpqr79 |
( |
N As |
Long, |
|
|
A() As |
Complex, |
|
|
Z() As |
Complex, |
|
|
Info As |
Long |
|
) |
| |
Roots of a polynomial (complex coefficients) (Companion matrix method)
- 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] | N | Degree 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
Call Cpqr79(N, A(), Z(), Info)
For I = 0 To N - 1
Next
Debug.Print "Info =", Info
End Sub
Function Cmplx(R As Double, Optional I As Double=0) As Complex Building complex number
Function Cimag(A As Complex) As Double Imaginary part of complex number
Function Creal(A As Complex) As Double Real part of complex number
Sub Cpqr79(N As Long, A() As Complex, Z() As Complex, Info As Long) Roots of a polynomial (complex coefficients) (Companion matrix method)
- Example Results
4 9.00000000000001
7.99999999999999 3.99999999999998
7.00000000000001 1.00000000000001
Info = 0
|