Solving quadratic programming using R

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 :

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];
eps = (sqrt(nsamples)-1)/sqrt(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


The original question asks about the error message Error in crossprod(r, q) : non-conformable arguments. The answer is that r must be specified with the same dimensions as b. So if b is 2x1 then r must also be 2x1.

A secondary question (from the comments) asks about why the system presented in the original question works in Matlab but not in R. The answer is that R and Matlab specify the problems differently. Matlab allows for inequality constraints to be entered separately from the equality constraints. However in R the constraints must all be of the form b<=Ax<=b+r (at least within the kernlab function ipop). So how may we mimic the original inequality constraints? The simple way is to make b very negative and to make r'=-b+r, where r' is your new r vector. Now we still have the same upper bound on the constraints because r'+b=-b+r+b=r. However we have put a lower bound on the constraints, too. My suggestion is to try solving the system with a few different values for b to see if the solution is consistent.


This is probably a better way to handle solving the program:

library(quadprog); dvec <- -f; Dmat <- H; Amat <- -t(A); bvec <- -rbind(4.26,-1.73); solve.QP(Dmat, dvec, Amat, bvec)

where these definitions depend on the previously defined R code.

Need Your Help

Development resources for Mono on PS3

c# mono playstation

I have been considering taking the plunge and installing Linux on my Playstation 3. As C# is my current language of choice, the next logical step would be to install Mono.

VS2008 debugging with firefox as default browser - how to make the debugger stop/close on exit?

visual-studio debugging firefox

I have Firefox as my default browser on my dev machine and when I start debugging from visual studio Firefox launches as I would expect and all the attributes of the experience are the same as IE e...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.