I'm trying to find the solution in the following problem:
Arbitrary values for reproducability:
AZ2k <- seq(1:14)
noAZ2k <- matrix(seq(1:25), 14, 50)
par <- rep(0.02 , 50)
vw <- function(w)
{
t(AZ2k - noAZ2k %*% par)%*%w%*%(AZ2k - noAZ2k %*% par )
}
vweights <- optim(diag(1,14), vw, gr = NULL,
method = c("L-BFGS-B"),
lower = 0, upper = 10000,control = list( factr = 1e4, maxit = 1000, pgtol = .01 ),
hessian = FALSE)
When I type in
t(AZ2k - noAZ2k %*% par)%*%diag(1,14)%*%(AZ2k - noAZ2k %*% par )
I get a result, however when I try to run the optimization it says that the values aren't fitting which is surprising to me.
I'm probably missing something totally obvious, but I just can't find where I went wrong, unless optim is just the wrong function to use, but I can't figure out the appropriate alternative.