R function solve.QP error "restrictions are incompatible, there is no solution!"

I am trying to start optimization using the solve.QP function (from the quadprog package) with the following parameters

R = matrix( c( 2.231113e-05,-4.816095e-05,-5.115287e-05, 0,2.989584e-05,4.212173e-06,0,0, 5.504990e-05), ncol=3, byrow=T)
b = c(-1,0,rep(0,ncol(R)))
C = cbind(rep(1,ncol(R)), diag(ncol(R)))
C = cbind(-rep(1,ncol(R)),C)
d = as.matrix(c(57621264,78057622,171342351),ncol=1)
H = solve.QP(Dmat = R, factorized = TRUE, dvec = d, Amat = C, bvec = b)

But I get an error

Error in solve.QP(Dmat = R, factorized = TRUE, dvec = d, Amat = C, bvec = b) : 
constraints are inconsistent, no solution!

However, when I use a different matrix for R

R2 = matrix( c( 0.05365071,-0.06364421,-0.04102565, 0, 0.08423283,-0.04048879,0,0,0.09659707), ncol=3, byrow=T)

call solve.QP

H = solve.QP(Dmat = R2, factorized = TRUE, dvec = d, Amat = C, bvec = b)

does not cause any problems. Now my question is: why in the first case there are problems.

Any help is much appreciated!

+4
source share
2 answers

, . -, meq, , , , meq = 0, , . , , ; .. > 0. , . , . , . , - .

------------ edit ---------------------------------- -----------

, , meq. , , , , , . , , R . , R . QP, , constrOptim. R R2- R2-, solve.QP R2.

R2 = matrix( c( 0.05365071,-0.06364421,-0.04102565, 0, 0.08423283,-0.04048879,0,0,0.09659707), ncol=3, byrow=T)
R = matrix( c( 2.231113e-05,-4.816095e-05,-5.115287e-05, 0,2.989584e-05,4.212173e-06,0,0, 5.504990e-05), ncol=3, byrow=T)
d = as.matrix(c(57621264,78057622,171342351),ncol=1)
start <- rep(1/(ncol(R)+1), ncol(R))
min_fn <- function(b, dvec, Dmat)  -t(dvec)%*%b +t(b)%*%Dmat%*%b/2
grad_min_fn <- function(b, dvec, Dmat) -dvec + Dmat%*%b
b = c(-1., 0, rep(0,ncol(R)))
C = cbind(rep(1,ncol(R)), diag(ncol(R)))
C = cbind(-rep(1,ncol(R)),C)
D <- t(solve(R))%*%solve(R)
constrOptim(theta=start, f=min_fn, grad=grad_min_fn, ui=t(C), ci=b,     control=list(reltol=10*.Machine$double.eps), 
        dvec=d, Dmat=D )

solve.QP solution for R2
$solution
[1] -1.025463e-10  0.000000e+00  1.000000e+00

constrOptim solution for R2
$par
[1] 2.479855e-15 1.178762e-14 1.000000e+00

R

 $par
[1] 9.272547e-17 5.958225e-14 1.040137e-01

constrOptim , solve.QP, .
, constrOptim solve.QP, .

+3

dvec . R Dmat, .. Dmat = M ^ T M, M = R ^ {- 1}. , :

M <- solve(R) 
Dmat <- t(M)%*%M

Dmat , dvec:

#  [,1]       [,2]       [,3]
#[1,] 2008893283 3236243201 1619059085
#[2,] 3236243201 6332319710 2522625866
#[3,] 1619059085 2522625866 1641403882

, , , - . , Dmat () dvec:

sc <- norm(Dmat,"2")
solve.QP(Dmat = Dmat/sc, dvec=d/sc, Amat=C, bvec=b, meq=0, factorized=FALSE )

# $solution
# [1] -1.220832e-17  0.000000e+00  1.043877e-01

, constrOptim .

Dmat dvec , -d^T b + 1/2 b^T D b sc*(-d^T b + 1/2 b^T D b) sc.

EDIT: , - :

nn2 = sqrt(norm(d,"2"))
H = solve.QP(Dmat = R*nn2, dvec = d/(nn2^2), Amat = C, bvec = b, factorized=TRUE)
#$solution
#[1] 0.0000000 0.0000000 0.1043877
+12

All Articles