|
|
◆ Rpzero2()
| Sub Rpzero2 |
( |
N As |
Long, |
|
|
A() As |
Double, |
|
|
Zr() As |
Double, |
|
|
Zi() As |
Double, |
|
|
IFlag As |
Long, |
|
|
S() As |
Double, |
|
|
Info As |
Long, |
|
|
Optional Iter As |
Long, |
|
|
Optional MaxIter As |
Long = 0 |
|
) |
| |
Roots of a polynomial (real coefficients) (2nd order simultaneous iterative method) (complex type is not used)
- Purpose
- This routine computes all roots of a polynomial p(z) with real coefficients by the 2nd order iterative method finding all roots simultaneously.
p(z) = a0*z^n + a1*z^(n-1) + ... + an
The obtained zeros are output to the separate real type variables for real and imaginary parts.
- 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). |
| [in,out] | Zr() | Array Zr(LZr - 1) (LZr >= N)
[in] Real parts of initial estimates for zeros. If these are unknown, set IFlag = 0 and it is not necessary to set estimates in Zr().
Note - Initial estimates must be separated, that is, distinct or not repeated.
[out] Real parts of the zeros |
| [in,out] | Zi() | Array Zi(LZi - 1) (LZi >= N)
[in] Imaginary parts of initial estimates for zeros. If these are unknown, set IFlag = 0 and it is not necessary to set estimates in Zi().
Note - Initial estimates must be separated, that is, distinct or not repeated.
[out] Imaginary parts of the obtained zeros. |
| [in] | IFlag | Flag 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 Zr() is invalid.
= -4: The argument Zi() is invalid.
= -6: The argument S() is invalid.
= 1: Maximum number of iterations exceeded. Best current estimates of the zeros are in Zr() and Zi(). 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_Rpzero2()
Const N As Long = 5
Dim A(N) As Double, Zr(N - 1) As Double, Zi(N - 1) As Double, 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 Rpzero2(N, A(), Zr(), Zi(), IFlag, S(), Info)
For I = 0 To N - 1
Debug.Print Zr(I), Zi(I), S(I)
Next
Debug.Print "Info =", Info
End Sub
Sub Rpzero2(N As Long, A() As Double, Zr() As Double, Zi() As Double, IFlag As Long, S() As Double, Info As Long, Optional Iter As Long, Optional MaxIter As Long=0) Roots of a polynomial (real coefficients) (2nd order simultaneous iterative method) (complex type is ...
- 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.
|