R index numeric(0) instead of 0

This is the whole thing and it still does not work. I guess the problem is the second Amat condition and the if else structure:

``````Dmat <- matrix(0,nrow= J, ncol=J)
diag(Dmat) <- 1
dvec <- rep(0,J)
dvec <- -hsmooth
Aeq <- matrix(nrow= J, ncol=0)
beq <- rep(0)
Amat <- matrix(0,J,2*J-3)
bvec <- vector(mode="numeric", length=2*J-3)

for(j in 1:J)
{
Amat[j-1,j-1] = -1
Amat[j,j-1]   = 1
bvec[j-1]     = Delta1
}

for(j in 2:J){
Amat[j,J-1+j-2]   = -1/ (Q[j] - Q[j-1])
if (j==2)
{Amat[j-1,J-1+j-2] = 1/(Q[j] - Q[j-1]) + 1/(Q[j-1] - 0)
}
else
{Amat[j-1,J-1+j-2] = 1/(Q[j] - Q[j-1]) + 1/(Q[j-1] - Q[j-2])
}
Amat[j-2,J-1+j-2] = -1/ (Q[j-1] - Q[j-2])
bvec[J-1+j-2]     = Delta2
}

solution1 <- solve.QP(Dmat, dvec, Amat, bvec, meq=0, factorized=FALSE)
``````

The math form is the following:

min sum(mj- m^), where j 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

I would really appreciate if some help here.

R index numeric(0) instead of 0