XLPack 7.0
XLPack Numerical Library (Excel VBA) Reference Manual
Loading...
Searching...
No Matches

◆ Cpzero()

Sub Cpzero ( N As  Long,
A() As  Complex,
Z() As  Complex,
IFlag As  Long,
S() As  Double,
Info As  Long,
Optional Iter As  Long,
Optional MaxIter As  Long = 0 
)

Roots of a polynomial (complex coefficients) (2nd order simultaneous iterative method)

Purpose
This routine computes all roots of a polynomial p(z) with complex coefficients by the 2nd order iterative method finding all roots simultaneously.
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).
[in,out]Z()Array Z(LZ - 1) (LZ >= N)
[in] Initial estimates for zeros. If these are unknown, set IFlag = 0 and it is not necessary to set estimates in Z().
  Note - Initial estimates must be separated, that is, distinct or not repeated.
[out] The obtained zeros.
[in]IFlagFlag to indicate if initial estimates of zeros are input.
= 0: No estimates are input.
<> 0: Zr() and Zi() contain estimates of zeros.
[out]S()Array S(LS - 1) (LS >= N)
Error bound for Zr() and Zi().
[out]Info= 0: Successful exit.
= -1: The argument N had an illegal value. (N < 1)
= -2: The argument A() is invalid or had an illegal value. (A(0) = 0)
= -3: The argument Z() is invalid.
= -5: The argument S() is invalid.
= 1: Maximum number of iterations exceeded. Best current estimates of the zeros are in Z(). Error bounds in S() are not calculated.
[out]Iter(Optional)
Number of iterations required to converge.
[in]MaxIter(Optional)
Maximum number of iterations. (default = 25 * N)
If MaxIter <= 0, the default value will be used.
Reference
SLATEC
Example Program
Solve the following algebraic equation.
x^3 + (-19-14i)*x^2 + (67+191i)*x + 116-612i = 0
The exact soplutions are 8 + 4i, 4 + 9i and 7 + i.
Sub Ex_Cpzero()
Const N As Long = 3
Dim A(N) As Complex, Z(N - 1) As Complex, S(N - 1) As Double
Dim IFlag As Long, 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)
IFlag = 0
Call Cpzero(N, A(), Z(), IFlag, S(), Info)
For I = 0 To N - 1
Debug.Print Creal(Z(I)), Cimag(Z(I)), S(I)
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 Cpzero(N As Long, A() As Complex, Z() As Complex, IFlag As Long, S() As Double, Info As Long, Optional Iter As Long, Optional MaxIter As Long=0)
Roots of a polynomial (complex coefficients) (2nd order simultaneous iterative method)
Example Results
8 4 6.12410216962375E-13
4 9 2.62419907575987E-13
7 1 2.49188840222312E-13
Info = 0