I've dealing with a quadratic programming problem as following, and my objective is to get a 49*1 vector.

$$\widehat{\boldsymbol{w}}^{0}(\tau):=\underset{\boldsymbol{w}(\tau) \in \mathbb{W}}{\arg \min }\left(\hat{\boldsymbol{\psi}}^{*}(\tau)-\hat{\boldsymbol{\Psi}}^{*}(\tau) \boldsymbol{w}(\tau)\right)^{\top}\left(\hat{\boldsymbol{\psi}}^{*}(\tau)-\hat{\Psi}^{*}(\tau) \boldsymbol{w}(\tau)\right) $$

where $\mathbb{W}:=\left\{\boldsymbol{w} \mid \boldsymbol{w} \in[0,1]^{N-1} \text { and } \boldsymbol{\iota}_{N-1}^{\top} \boldsymbol{w}=1\right\}$

Thus when I use solve.QP function in R, I define $$psi1 = \hat{\boldsymbol{\psi}}^{*}(\tau)$$ $$psi2 = \hat{\boldsymbol{\Psi}}^{*}(\tau)$$ I suppose my constraint $A^{\top}\boldsymbol{w}\geq b_{0}$ are $$ A=\begin{bmatrix} 1&1&1&\ldots&1&1\\ 1&0&0&\ldots&0&0\\ 0&1&0&\ldots&0&0\\ 0&0&1&\ldots&0&0\\ \vdots & \vdots & \vdots& \ddots & \vdots &\vdots \\ 0&0&0&\ldots&1&0\\ 0&0&0&\ldots&0&1\\ -1&0&0&\ldots&0&0\\ 0&-1&0&\ldots&0&0\\ 0&0&-1&\ldots&0&0\\ \vdots & \vdots & \vdots& \ddots & \vdots &\vdots \\ 0&0&0&\ldots&-1&0\\ 0&0&0&\ldots&0&-1\\ \end{bmatrix} $$ $$ b_{0}=(1,0,0,0,\cdots,0,0,-1,-1,-1,\cdots,-1,-1)^{\top} $$

Dmat = (t(psi2)%*%psi2)/2
dvec = t(2*(t(psi1)%*%psi2))
Amat = t(rbind(rep(1,(unit-1)),diag(1,49,49),diag(-1,49,49))
bvec = c(1,rep(0,(unit-1)),rep(-1,(unit-1)))

However, I get a solution like this: enter image description here

Obviously there are some negative numbers in this solution and it doesn't satisfy my constraint, and I'm wondering why this happens. Thanks a lot.

  • 2
    $\begingroup$ Please show all your code. $\endgroup$ – Bob Jansen Apr 3 at 16:49
  • $\begingroup$ I have edited my question and updated my code, thanks a lot. $\endgroup$ – Toxique Apr 3 at 17:21
  • $\begingroup$ Can you elaborate further on what quadratic programming problem you're trying to solve (maybe formulate it mathematically)? $\endgroup$ – Pleb Apr 3 at 18:35
  • $\begingroup$ I have edited my question with all codes and the objective function, thanks a lot. $\endgroup$ – Toxique Apr 4 at 1:30
  • $\begingroup$ Please stop significantly changing the question. My answer was valid until the problem turned out to be something else entirely. $\endgroup$ – Bob Jansen Apr 4 at 5:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.