Re: [R] Fwd: Quadratic programming, for loop

2018-07-30 Thread Maija Sirkjärvi
Thanks a lot! I got the main part working (after a relaxing holiday). However I still have some problems with the conditions. The looping is not working properly, but this is not really an QP problem anymore. It's more about that R runs the loop differently than c++, I guess. Thanks a lot for

Re: [R] Fwd: Quadratic programming, for loop

2018-06-29 Thread Berwin A Turlach
G'day Maija, On Wed, 27 Jun 2018 08:48:08 +0300 Maija Sirkjärvi wrote: > Thanks for your reply! Unfortunately something is still wrong. > > After the transpose, dvec and Amat are still incompatible. > > > d <- -hsmooth > > dvec <- t(d) > > c <- dvec*Amat > Error in dvec * Amat :

Re: [R] Fwd: Quadratic programming, for loop

2018-06-26 Thread Maija Sirkjärvi
Thanks for your reply! Unfortunately something is still wrong. After the transpose, dvec and Amat are still incompatible. > d <- -hsmooth > dvec <- t(d) > c <- dvec*Amat Error in dvec * Amat : non-conformable arrays Moreover, I don't understand the following: > If dvec is of length *J*, then b

Re: [R] Fwd: Quadratic programming, for loop

2018-06-26 Thread Spencer Graves
  sos::findFn('{quadratic programming}') just identified 156 help pages in 68 packages containing the term "quadratic programming".  The function mentioned by Berwin Turlach, "solve.QP", is in package "quadprog", which has not been updated since 2016-12-20.  I've used qudprod successfully,

Re: [R] Fwd: Quadratic programming, for loop

2018-06-26 Thread Jeff Newmiller
The recommended (see the Posting Guide) way to resolve questions like this is to post a reproducible example so we can see the problem occur in our R session. There are a number of Internet resources that can help you get this right such as [1][2][3]. Note that one key to success is to learn

Re: [R] Fwd: Quadratic programming, for loop

2018-06-26 Thread Berwin A Turlach
G'day all, On Tue, 26 Jun 2018 11:16:55 +0300 Maija Sirkjärvi wrote: > It seems that my Amat and dvec are incompatible. Amat is a matrix of > zeros size: *2*J-3,J* and dvec is a vector of length *J*. There > should be no problem, but apparently there is. [...] solve.QP solves the quadratic

Re: [R] Fwd: Quadratic programming, for loop

2018-06-26 Thread Maija Sirkjärvi
Thanks for the reply! dvec, thus hsmooth, has the same length J. It shouldn't be the problem. 2018-06-26 11:24 GMT+03:00 Eric Berger : > The statement > > dvec <- -hsmooth > > looks like it might be the source of the problem, depending on what > hsmooth is. > > > On Tue, Jun 26, 2018 at 11:16

Re: [R] Fwd: Quadratic programming, for loop

2018-06-26 Thread Eric Berger
The statement dvec <- -hsmooth looks like it might be the source of the problem, depending on what hsmooth is. On Tue, Jun 26, 2018 at 11:16 AM, Maija Sirkjärvi wrote: > Thanks for the reply! I got that figured out, but still have some problems > with the quadratic programming. > > It seems

Re: [R] Fwd: Quadratic programming, for loop

2018-06-26 Thread Maija Sirkjärvi
Thanks for the reply! I got that figured out, but still have some problems with the quadratic programming. It seems that my Amat and dvec are incompatible. Amat is a matrix of zeros size: *2*J-3,J* and dvec is a vector of length *J*. There should be no problem, but apparently there is. The piece

Re: [R] Fwd: Quadratic programming, for loop

2018-06-14 Thread Boris Steipe
Keep replies on list please. You are not accessing a value from vector Q if you access the zero'th element! R > Q <- c(3, 5, 8) R > Q[0] numeric(0) R > Q[1] [1] 3 R > Q[2] [1] 5 In the first iteration of the loop j is 2 thus j-2 is 0 and that's the reason for the error message: you are trying

Re: [R] Fwd: Quadratic programming, for loop

2018-06-13 Thread Boris Steipe
Q[j-2] gives you Q[0] in your first inner loop iteration. R arrays start at one. B. > On 2018-06-13, at 07:21, Maija Sirkjärvi wrote: > > Amat[J-1+j-2,j-1]= 1/(Q[j] - Q[j-1]) + 1/(Q[j-1] - Q[j-2]) __ R-help@r-project.org mailing list -- To

[R] Fwd: Quadratic programming, for loop

2018-06-13 Thread Maija Sirkjärvi
Hi! I have a quadratic optimization problem and I have some difficulties coding it with R. The math version of the problem looks like this: min sum(mj -mj^)^2 which goes from 1 to J st. mj-1 <= mj - delta1 1/(Qj-1 -Qj-2)(mj-2 -mj-1) <= 1/(Qj -Qj-1 ) (mj-1 - mj) -delta2 And I'm coding it like