The R Project SVN R

Rev

Rev 61160 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 61160 Rev 61168
Line 111... Line 111...
111
## but needs a feasible starting value
111
## but needs a feasible starting value
112
#
112
#
113
# from example(solve.QP) in 'quadprog'
113
# from example(solve.QP) in 'quadprog'
114
# no derivative
114
# no derivative
115
fQP <- function(b) {-sum(c(0,5,0)*b)+0.5*sum(b*b)}
115
fQP <- function(b) {-sum(c(0,5,0)*b)+0.5*sum(b*b)}
116
Amat       <- matrix(c(-4,-3,0,2,1,0,0,-2,1),3,3)
116
Amat       <- matrix(c(-4,-3,0,2,1,0,0,-2,1), 3, 3)
117
bvec       <- c(-8,2,0)
117
bvec       <- c(-8, 2, 0)
118
constrOptim(c(2,-1,-1), fQP, NULL, ui = t(Amat), ci = bvec)
118
constrOptim(c(2,-1,-1), fQP, NULL, ui = t(Amat), ci = bvec)
119
# derivative
119
# derivative
120
gQP <- function(b) {-c(0,5,0)+b}
120
gQP <- function(b) {-c(0, 5, 0) + b}
121
constrOptim(c(2,-1,-1), fQP, gQP, ui = t(Amat), ci = bvec)
121
constrOptim(c(2,-1,-1), fQP, gQP, ui = t(Amat), ci = bvec)
122
 
122
 
123
## Now with maximisation instead of minimisation
123
## Now with maximisation instead of minimisation
124
hQP <- function(b) {sum(c(0,5,0)*b)-0.5*sum(b*b)}
124
hQP <- function(b) {sum(c(0,5,0)*b)-0.5*sum(b*b)}
125
constrOptim(c(2,-1,-1), hQP, NULL, ui = t(Amat), ci = bvec,
125
constrOptim(c(2,-1,-1), hQP, NULL, ui = t(Amat), ci = bvec,