E04YBF checks that a user-supplied subroutine for evaluating the second derivative term of the Hessian matrix of a sum of squares is consistent with a user-supplied subroutine for calculating the corresponding first derivatives.
SUBROUTINE E04YBF ( |
M, N, LSQFUN, LSQHES, X, FVEC, FJAC, LDFJAC, B, LB, IW, LIW, W, LW, IFAIL) |
INTEGER |
M, N, LDFJAC, LB, IW(LIW), LIW, LW, IFAIL |
REAL (KIND=nag_wp) |
X(N), FVEC(M), FJAC(LDFJAC,N), B(LB), W(LW) |
EXTERNAL |
LSQFUN, LSQHES |
|
Routines for minimizing a sum of squares of
m nonlinear functions (or ‘residuals’),
fix1,x2,…,xn, for
i=1,2,…,m and
m≥n, may require you to supply a subroutine to evaluate the quantities
for
j=1,2,…,n and
k=1,2,…,j. E04YBF is designed to check the
bjk calculated by such user-supplied subroutines. As well as the routine to be checked (
LSQHES), you must supply a subroutine (
LSQFUN) to evaluate the
fi and their first derivatives, and a point
x=x1,x2,…,xnT at which the checks will be made. Note that E04YBF checks routines of the form required by
E04HEF. E04YBF is essentially identical to CHKLSH in the NPL Algorithms Library.
E04YBF first calls user-supplied subroutines
LSQFUN and
LSQHES to evaluate the first derivatives and the
bjk at
x. Let
J denote the
m by
n matrix of first derivatives of the residuals. The Hessian matrix of the sum of squares,
is calculated and projected onto two orthogonal vectors
y and
z to give the scalars
yTGy and
zTGz respectively. The same projections of the Hessian matrix are also estimated by finite differences, giving
respectively, where
g denotes the gradient vector of the sum of squares at the point in brackets and
h is a small positive scalar. If the relative difference between
p and
yTGy or between
q and
zTGz is judged too large, an error indicator is set.
None.
If on entry
IFAIL=0 or
-1, explanatory error messages are output on the current error message unit (as defined by
X04AAF).
IFAIL is set to
2 if
where
h is set equal to
ε (
ε being the
machine precision as given by
X02AJF) and other quantities are defined as in
Section 3.
Suppose that it is intended to use
E04HEF to find least squares estimates of
x1,x2 and
x3 in the model
using the
15 sets of data given in the following table.
This example program could be used to check the
bjk calculated by
LSQHES required. (The call of E04YBF is preceded by a call of
E04YAF to check
LSQFUN which calculates the first derivatives.)