[R] using solve.qp without a quadratic term

markleeds at verizon.net markleeds at verizon.net
Sat Dec 22 02:38:19 CET 2007


I was playing around with a simple example using solve.qp ( function is in the quadprog package ) and the code is below. ( I'm not even sure there if there is a reasonable solution because I made the problem up  ). 

But, when I try to use solve.QP to solve it, I get the error that D in the quadratic function is not positive
definite. This is because Dmat is zero
because I don't have a quadratic term in my
objective function. So, I was wondering if
it was possible to use solve.QP when there isn't
a quadratic term in the objective function.  

I imagine that there are other functions in R that can be used but I would like to use solve.QP because, in my real problem,
I will have a lot of fairly complex constraints
and solve.QP provides a very nice way for implementing
them. Maybe there is another linear solver that allows you to implement hundreds of constraints just solve.QP that I am unaware of ? Thanks for any suggestions.

# IN THE CODE BELOW, WE MINIMIZE 

# -3*b1 + 4*b2 + 6*b3

# SUBJECT TO

# b1 + b2 + b3 >=0
# -(b1  b2 + b3) >= 0 
# IE : b1 + b2 + b3 = 0.

Dmat <- matrix(0,3,3)          # QUADRATIC TERM
dvec <- c(-3,4,6)              # LINEAR TERM
Amat <- matrix(c(1,-1,0,1,-1,0,1,-1,0),3,3)

#print(Amat)

bvec = c(0,0,0)                  # THIRD ZERO IS SAME AS NO CONSTRAINT

result <- solve.QP(Dmat, dvec, Amat)



More information about the R-help mailing list