hybrd

The purpose of hybrd is to find a zero of a system of n nonlinear functions in n variables by a modification of the Powell Hybrid Method. The user must provide a function which calculates the functions. The Jacobian is then calculated by a forward-difference approximation.

void
hybrd
(
Real
Func
)
(
Func fcn
,
size_t n
,
Real* x
,
Real* fvec
,
Real xtol
,
uint maxfev
,
size_t ml
,
size_t mu
,
Real epsfcn
,
Real* diag
,
int mode
,
Real factor
,
int nprint
,
out int info
,
out uint nfev
,
Real* fjac
,
size_t ldfjac
,
Real* r
,
size_t lr
,
Real* qtf
,
Real* wa1
,
Real* wa2
,
Real* wa3
,
Real* wa4
)

Parameters

fcn Func

the user-supplied function or delegate which calculates the functions. The function referenced by fcn must be declared in an external statement in the user calling program, and should be written as follows.

void foo (size_t n,real* x, real* fvec, int iflag)
{
    // calculate the functions at x and
    // return this vector in fvec.
}

The value of iflag should not be changed by the function unless the user wants to terminate execution of hybrd. In this case set iflag to a negative integer.

n size_t

a positive integer input variable set to the number of functions and variables.

x Real*

an array of length n. On input x must contain an initial estimate of the solution vector. On output x contains the final estimate of the solution vector.

fvec Real*

an output array of length n which contains the functions evaluated at the output x.

xtol Real

a nonnegative input variable. Termination occurs when the relative error between two consecutive iterates is at most xtol.

maxfev uint

a positive integer input variable. Termination occurs when the number of calls to fcn is at least maxfev by the end of an iteration.

ml size_t

a nonnegative integer input variable which specifies the number of subdiagonals within the band of the jacobian matrix. If the Jacobian is not banded, set ml to at least n - 1.

mu size_t

a nonnegative integer input variable which specifies the number of superdiagonals within the band of the jacobian matrix. If the Jacobian is not banded, set mu to at least n - 1.

epsfcn Real

an input variable used in determining a suitable step length for the forward-difference approximation. This approximation assumes that the relative errors in the functions are of the order of epsfcn. If epsfcn is less than the machine precision, it is assumed that the relative errors in the functions are of the order of the machine precision.

diag Real*

an array of length n. If mode = 1 (see below), diag is internally set. If mode = 2, diag must contain positive entries that serve as multiplicative scale factors for the variables.

mode int

an integer input variable. If mode = 1, the variables will be scaled internally. If mode = 2, the scaling is specified by the input diag. Other values of mode are equivalent to mode = 1.

factor Real

a positive input variable used in determining the initial step bound. This bound is set to the product of factor and the Euclidean norm of diag*x if nonzero, or else to factor itself. In most cases factor should lie in the interval (.1,100.). 100. is a generally recommended value.

nprint int

an integer input variable that enables controlled printing of iterates if it is positive. In this case, fcn is called with iflag = 0 at the beginning of the first iteration and every nprint iterations thereafter and immediately prior to return, with x and fvec available for printing. If nprint is not positive, no special calls of fcn with iflag = 0 are made.

info int

an integer output variable. If the user has terminated execution, info is set to the (negative) value of iflag. See description of fcn. Otherwise, info is set as follows.

0:  improper input parameters.

1:  relative error between two consecutive iterates
    is at most xtol.

2:  number of calls to fcn has reached or exceeded
    maxfev.

3:  xtol is too small. no further improvement in
    the approximate solution x is possible.

4:  iteration is not making good progress, as
    measured by the improvement from the last
    five Jacobian evaluations.

5:  iteration is not making good progress, as
    measured by the improvement from the last
    ten iterations.
nfev uint

an integer output variable set to the number of calls to fcn.

fjac Real*

an output n by n array which contains the orthogonal matrix Q produced by the QR factorization of the final approximate Jacobian.

ldfjac size_t

a positive integer input variable not less than n which specifies the leading dimension of the array fjac.

r Real*

an output array of length lr which contains the upper triangular matrix produced by the QR factorization of the final approximate Jacobian, stored rowwise.

lr size_t

a positive integer input variable not less than (n*(n+1))/2.

qtf Real*

an output array of length n which contains the vector (Q transpose)*fvec.

wa1 Real*

work array of length n.

wa2 Real*

work array of length n.

wa3 Real*

work array of length n.

wa4 Real*

work array of length n.

Meta