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

◆ Rpzero()

Sub Rpzero ( N As  Long,
A() As  Double,
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 (real coefficients) (Netwon method)

Purpose
This routine computes all roots of a polynomial p(z) with real coefficients by Netwon method.
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)
Real 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^5 + 2*x^3 + 2*x^2 - 15*x + 10 = 0
The exact solutions are 1(double root), -2 and ±√5i.
Sub Ex_Rpzero()
Const N As Long = 5
Dim A(N) As Double, Z(N - 1) As Complex, S(N - 1) As Double
Dim IFlag As Long, Info As Long, I As Long
A(0) = 1: A(1) = 0: A(2) = 2: A(3) = 2: A(4) = -15: A(5) = 10
IFlag = 0
Call Rpzero(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
Example Results
1.0000000135981 2.14625358292393E-08 1.26597932122911E-07
1.48298437403299E-18 2.23606797749979 8.99528943854828E-15
-2 1.15041631099093E-19 7.53855142372064E-15
7.94241311875315E-17 -2.23606797749979 9.06723080094738E-15
0.999999987046461 -2.24784161738852E-08 1.26578540844987E-07
Info = 0
Note - Only half precision for double roots.