With regards to a quadratic programme, how would I set up an objective function like
min ∑a_i (x_i )^2
in the matrix form for packages “quadprog” or “limSolve” (for this package I'm not sure if it needs to be in matrix form)?
From the discussion I have seen so far, there has been no multiplication of the quadratic term.
Let's consider a simple linearly constrained quadratic program of the form you have mentioned:
Solution with the
quadprogpackageThe
quadprogpackage accepts models of the following form:To get our problem into this form, we need to construct a matrix
Dwith(2*0.5 2*0.7)as the main diagonal, as well as a matrixAwith our three constraints and a right hand sideb0:Now we can feed this to
solve.QP:Solution with the
limSolvepackageThe
limSolvepackage'slseifunction accepts models of the following form:To obtain our objective function we need to construct matrix
Awith(sqrt(0.5) sqrt(0.7))as the main diagonal, setbto be the 0 vector, as well as matrices and vectors encoding the other information:Now we can feed this information to
lsei: