| searchZeros {nleqslv} | R Documentation |
Solve a nonlinear equation system with multiple roots from multiple initial estimates
Description
This function solves a system of nonlinear equations with nleqlsv
for multiple initial estimates of the roots.
Usage
searchZeros(x, fn, digits=4, ... )
Arguments
x |
A matrix with each row containing an initial guess of the roots. |
fn |
A function of |
digits |
integer passed to |
... |
Further arguments to be passed to |
Details
Each row of x is a vector of initial estimates for the argument
x of nleqslv.
The function runs nleqslv for each row of the matrix x.
The first initial value is treated separately and slightly differently from the
other initial estimates. It is used to check if all
arguments in ... are valid arguments for nleqslv and the function
to be solved. This is done by running nleqslv with no condition handling.
If an error is then detected an error message is issued and the function stops.
For the remaining initial estimates nleqslv is executed silently.
Only solutions for which the nleqslv termination code tcode equals 1
are regarded as valid solutions. The rounded solutions (after removal of duplicates)
are used to order the solutions in increasing order.
These rounded solutions are not included in the return value of the function.
Value
If no solutions are found NULL is returned.
Otherwise a list containing the following components is returned
xa matrix with each row containing a unique solution (unrounded)
xfnorma vector of the function criterion associated with each row of the solution matrix
x.fnorma vector containing the function criterion for every converged result
idxcvga vector containing the row indices of the matrix of initial estimates for which function value convergence was achieved
idxxtola vector containing the row indices of the matrix of initial estimates for which x-value convergence was achieved
idxnocvga vector containing the row indices of the matrix of initial estimates which lead to an
nleqslvtermination code > 2idxfatala vector containing the row indices of the matrix of initial estimates for which a fatal error occurred that made
nleqslvstopxstarta matrix of the initial estimates corresponding to the solution matrix
cvgstarta matrix of all initial estimates for which convergence was achieved
Examples
# Dennis Schnabel example 6.5.1 page 149 (two solutions)
set.seed(123)
dslnex <- function(x) {
y <- numeric(2)
y[1] <- x[1]^2 + x[2]^2 - 2
y[2] <- exp(x[1]-1) + x[2]^3 - 2
y
}
xstart <- matrix(runif(50, min=-2, max=2),ncol=2)
ans <- searchZeros(xstart,dslnex, method="Broyden",global="dbldog")
ans
# more complicated example
# R. Baker Kearfott, Some tests of Generalized Bisection,
# ACM Transactions on Methematical Software, Vol. 13, No. 3, 1987, pp 197-220
# A high-degree polynomial system (section 4.3 Problem 12)
# There are 12 real roots (and 126 complex roots to this system!)
hdp <- function(x) {
f <- numeric(length(x))
f[1] <- 5 * x[1]^9 - 6 * x[1]^5 * x[2]^2 + x[1] * x[2]^4 + 2 * x[1] * x[3]
f[2] <- -2 * x[1]^6 * x[2] + 2 * x[1]^2 * x[2]^3 + 2 * x[2] * x[3]
f[3] <- x[1]^2 + x[2]^2 - 0.265625
f
}
N <- 40 # at least to find all 12 roots
set.seed(123)
xstart <- matrix(runif(3*N,min=-1,max=1), N, 3) # N initial guesses, each of length 3
ans <- searchZeros(xstart,hdp, method="Broyden",global="dbldog")
ans$x