|
|
◆ rpzero2()
| def rpzero2 |
( |
n |
, |
|
|
a |
, |
|
|
rr |
, |
|
|
ri |
, |
|
|
s |
, |
|
|
iflag |
= 0, |
|
|
maxiter |
= 100 |
|
) |
| |
Roots of a polynomial (real coefficients) (Netwon method) (complex type is not used)
- Purpose
- rpzero2 computes all roots of a polynomial p(z) with real coefficients by Netwon method.
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.
- Returns
- (iter, info)
iter (int):
Number of iterations required to converge.
info (int):
= 0: Successful exit
= -1: The argument n had an illegal value (n < 1)
= -2: The argument a is invalid (e.g. a[0] = 0)
= -3: The argument rr is invalid. = -4: The argument ri is invalid. = -5: The argument s is invalid. = -7: The argument maxiter had an illegal value (maxiter <= 0)
= 1: Failed to converge after maxiter iterations. Best current estimates of the zeros are in rr and ri. Error bounds in s are not calculated.
- Parameters
-
| [in] | n | Degree of polynomial. (n >= 1) |
| [in] | a | Numpy ndarray (1-dimensional, float, length n + 1)
Real coefficient vector of p(z) (a0 to an). |
| [in,out] | rr | Numpy ndarray (1-dimensional, float, length 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 rr.
Note - Initial estimates must be separated, that is, distinct or not repeated.
[out] Real part of the obtained zeros. |
| [in,out] | ri | Numpy ndarray (1-dimensional, float, length 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 ri.
Note - Initial estimates must be separated, that is, distinct or not repeated.
[out] Imaginary part of the obtained zeros. |
| [out] | s | Numpy ndarray (1-dimensional, float, length n)
Error bound for the obtained zeros. |
| [in] | iflag | (Optional)
Flag to indicate if initial estimates of zeros are input. (default = 0)
= 0: No estimates are input.
!= 0: rr and ri contain estimates of zeros. |
| [in] | maxiter | (Optional)
Maximum number of iterations. (maxitr >= 1) (default = 100) |
- 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. def TestRpzero2():
n = 5;
a = np.array([1.0, 0.0, 2.0, 2.0, -15.0, 10.0])
rr = np.empty(n)
ri = np.empty(n)
s = np.empty(n)
iter, info = rpzero2(n, a, rr, ri, s)
for i in range(n):
print(rr[i], ri[i], s[i])
print(iter, info)
def rpzero2(n, a, rr, ri, s, iflag=0, maxiter=100) Roots of a polynomial (real coefficients) (Netwon method) (complex type is not used)
- Example Results
>>> TestRpzero2()
1.0000000135981033 2.146253582923928e-08 1.265979321229113e-07
1.4829843740329862e-18 2.23606797749979 8.99528943854828e-15
-2.0 1.1504163109909317e-19 7.53855142372064e-15
7.942413118753155e-17 -2.23606797749979 9.067230800947384e-15
0.9999999870464613 -2.247841617388521e-08 1.2657854084498727e-07
30 0
Note - Only half precision for double roots.
|