testnslv {nleqslv}R Documentation

Test different methods for solving with nleqslv

Description

The function tests different methods and global strategies for solving a system of nonlinear equations with nleqslv

Usage

testnslv(x, fn, jac=NULL, ...,
          method = c("Newton", "Broyden"),
          global = c("cline", "qline", "gline", "pwldog", "dbldog", "hook", "none"),
          Nrep=0L, title=NULL
        )

Arguments

x

A numeric vector with an initial guess of the root.

fn

A function of x returning the function values.

jac

A function to return the Jacobian for the fn function. For a vector valued function fn the Jacobian must be a numeric matrix of the correct dimensions. For a scalar valued function fn the jac function may return a scalar. If not supplied numerical derivatives will be used.

...

Further arguments to be passed to fn and jac and nleqslv.

method

The methods to use for finding a solution.

global

The global strategies to test. The argument may consist of several possibly abbreviated items.

Nrep

Number of repetitions to apply. Default is no repetitions.

title

a description of this experiment.

Details

The function solves the function fn with nleqslv for the specified methods and global strategies. When argument Nrep has been set to a number greater than or equal to 1, repetitions of the solving process are performed and the used CPU time in seconds is recorded.

If checking a user supplied jacobian is enabled, then testnslv will stop immediately when a possibly incorrect jacobian is detected.

Value

testnslv returns an object of class "test.nleqslv" which is a list containing the following elements

call

the matched call

out

a dataframe containing the results with the following columns

Method

method used.

Global

global strategy used.

termcd

termination code of nleqslv.

Fcnt

number of function evaluations used by the method and global strategy. This excludes function evaluations made when computing a numerical Jacobian.

Jcnt

number of Jacobian evaluations.

Iter

number of outer iterations used by the algorithm.

Message

a string describing the termination code in an abbreviated form.

Fnorm

square of the euclidean norm of the vector of function results divided by 2.

cpusecs

CPU seconds used by the requested number of repetitions (only present when argument Nrep is not 0).

title

the description if specified

The abbreviated strings are

Fcrit

Convergence of function values has been achieved.

Xcrit

This means that the relative distance between two consecutive x-values is smaller than xtol.

Stalled

The algorithm cannot find an acceptable new point.

Maxiter

Iteration limit maxit exceeded.

Illcond

Jacobian is too ill-conditioned.

Singular

Jacobian is singular.

BadJac

Jacobian is unusable.

ERROR

nleqslv stopped because of a fatal error.

Warning

Any nleqslv error message will be displayed immediately and an error for the particular combination of method and global strategy will be recorded in the final dataframe.

Examples

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 <- c(0.5,0.5)
fstart <- dslnex(xstart)
testnslv(xstart,dslnex)
# this will encounter an error
xstart <- c(2.0,0.5)
fstart <- dslnex(xstart)
testnslv(xstart,dslnex)

[Package nleqslv version 3.3.5 Index]