e04ya {NAGFWrappers} R Documentation

## e04ya: Check user's function for calculating Jacobian of first derivatives

### Description

e04ya checks that a user-supplied function for evaluating a vector of functions and the matrix of their first derivatives produces derivative values which are consistent with the function values calculated.

### Usage

e04ya(m, lsqfun, x,
n = nrow(x))


### Arguments

 m integer lsqfun function lsqfun must calculate the vector of values f_i(x) and their first derivatives ( \partial f_i)/( \partial x_j) at any point x. (The minimization functions mentioned in the Description in Fortran library documentation give you the option of resetting a argument to terminate immediately. e04ya will also terminate immediately, without finishing the checking process, if the argument in question is reset.) (IFLAG,FVEC,FJAC) = lsqfun(iflag,m,n,xc,ldfjac)  x double array x[j] for j=1 . . . n, must be set to the coordinates of a suitable point at which to check the derivatives calculated by lsqfun. ‘Obvious’ settings, such as 0 or 1, should not be used since, at such particular points, incorrect terms may take correct values (particularly zero), so that errors can go undetected. For a similar reason, it is preferable that no two elements of x should have the same value. n integer: default = nrow(x) The number m of residuals, f_i(x), and the number n of variables, x_j.

### Details

R interface to the NAG Fortran routine E04YAF.

### Value

 FVEC double array Unless you set iflag negative in the first call of lsqfun, fvec[i] contains the value of f_i at the point supplied by you in x for i=1 . . . m. FJAC double array Unless you set iflag negative in the first call of lsqfun, fjac[i, j] contains the value of the first derivative ( \partial f_i)/( \partial x_j) at the point given in x, as calculated by lsqfun for j=1 . . . n for i=1 . . . m. IFAIL integer ifail =0 unless the function detects an error or a warning has been flagged (see the Errors section in Fortran library documentation).

NAG

### Examples


ifail <- 0
lsqfun = function(iflag, m, n, xc, ljc) {

fvec <- as.matrix(mat.or.vec(m, 1))
fjacc <- as.matrix(mat.or.vec(ljc, n))
for (i in c(1:m)) {
denom <- xc %*% t[i, 2] + xc %*% t[i, 3]

if (iflag != 1) {

fvec[i] <- xc + t[i, 1]/denom - y[i]

}
if (iflag != 0) {

fjacc[i, 1] <- 1

dummy <- -1/(denom %*% denom)

fjacc[i, 2] <- t[i, 1] %*% t[i, 2] %*% dummy

fjacc[i, 3] <- t[i, 1] %*% t[i, 3] %*% dummy

}
}
list(IFLAG = as.integer(iflag), FVEC = as.matrix(fvec), FJAC = as.matrix(fjacc))
}

m <- 15

x <- matrix(c(0.19, -1.34, 0.88), nrow = 3, ncol = 1,
byrow = TRUE)

iw <- as.matrix(mat.or.vec(0, 0))

w <- as.matrix(mat.or.vec(69, 1))

y <- matrix(c(0.14, 0.18, 0.22, 0.25, 0.29, 0.32,
0.35, 0.39, 0.37, 0.58, 0.73, 0.96, 1.34, 2.1, 4.39), nrow = 1,
ncol = 15, byrow = TRUE)

t <- matrix(c(1, 15, 1, 2, 14, 2, 3, 13, 3, 4, 12,
4, 5, 11, 5, 6, 10, 6, 7, 9, 7, 8, 8, 8, 9, 7, 7, 10, 6,
6, 11, 5, 5, 12, 4, 4, 13, 3, 3, 14, 2, 2, 15, 1, 1), nrow = 15,
ncol = 3, byrow = TRUE)

e04ya(m, lsqfun, x)



[Package NAGFWrappers version 24.0 Index]