Solving quadratic programming using R

Posted by user702846 on Stack Overflow See other posts from Stack Overflow or by user702846
Published on 2012-09-09T22:48:17Z Indexed on 2012/09/11 15:38 UTC
Read the original article Hit count: 220

Filed under:
|

I would like to solve the following quadratic programming equation using ipop function from kernlab :

min 0.5*x'*H*x + f'*x  
subject to:  A*x <= b   
Aeq*x = beq  
LB <= x <= UB 

where in our example H 3x3 matrix, f is 3x1, A is 2x3, b is 2x1, LB and UB are both 3x1.

edit 1 My R code is :

library(kernlab)
H <- rbind(c(1,0,0),c(0,1,0),c(0,0,1))
f = rbind(0,0,0)
A = rbind(c(1,1,1), c(-1,-1,-1))
b = rbind(4.26, -1.73)
LB = rbind(0,0,0)
UB = rbind(100,100,100)
> ipop(f,H,A,b,LB,UB,0)
Error in crossprod(r, q) : non-conformable arguments

I know from matlab that is something like this :

H = eye(3);
f = [0,0,0];
nsamples=3;
eps = (sqrt(nsamples)-1)/sqrt(nsamples);
A=ones(1,nsamples);
A(2,:)=-ones(1,nsamples);
b=[nsamples*(eps+1); nsamples*(eps-1)];

Aeq = [];
beq = [];
LB = zeros(nsamples,1);
UB = ones(nsamples,1).*1000;

[beta,FVAL,EXITFLAG] = quadprog(H,f,A,b,Aeq,beq,LB,UB);

and the answer is a vector of 3x1 equals to [0.57,0.57,0.57];

However when I try it on R, using ipop function from kernlab library ipop(f,H,A,b,LB,UB,0)) and I am facing Error in crossprod(r, q) : non-conformable arguments

I appreciate any comment

© Stack Overflow or respective owner

Related posts about r

    Related posts about machine-learning