|
|
◆ rpzero2()
| function rpzero2 |
( |
n::Integer |
, |
|
|
a::Array{Float64} |
, |
|
|
rr::Array{Float64} |
, |
|
|
ri::Array{Float64} |
, |
|
|
s::Array{Float64} |
, |
|
|
iflag::Integer |
= 0, |
|
|
maxiter::Integer(keyword argument) |
= 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 (Int32):
Number of iterations required to converge.
info (Int32):
= 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 | 1-dimensional array (Float64, n + 1)
Real coefficient vector of p(z) (a0 to an). |
| [in,out] | rr | 1-dimensional array (Float64, 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 | 1-dimensional array (Float64, 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 | 1-dimensional array (Float64, 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 (keyword argument))
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. function TestRpzero2()
n = 5
a = [ 1.0, 0.0, 2.0, 2.0, -15.0, 10.0 ]
rr = Vector{Cdouble}(undef, n)
ri = Vector{Cdouble}(undef, n)
s = Vector{Cdouble}(undef, n)
iter, info = rpzero2(n, a, rr, ri, s)
for i = 1:n
println(rr[i], " ", ri[i], " ", s[i])
end
println("iter = ", iter, ", info = ", info)
end
function rpzero2(n::Integer, a::Array{Float64}, rr::Array{Float64}, ri::Array{Float64}, s::Array{Float64}, iflag::Integer=0, maxiter::Integer(keyword argument)=100) Roots of a polynomial (real coefficients) (Netwon method) (complex type is not used)
- Example Results
> TestRpzero2()
1.0000000135981033 2.146253582923928e-8 1.265979321229113e-7
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-8 1.2657854084498727e-7
iter = 30, info = 0
Note - Only half precision for double roots.
|