1

I would like to solve a QP/LP problem in MatLab using CVXGEN. I have preference for CVXGEN over CVX, since CVXGEN is much faster. In particular, I would like to solve

min f(x) s.t. x in X

where f(x) is in quadratic form and X is compact, convex, and defined by linear functions. The size of the problem varies depending on the run. I would like to automate the procedure as much as possible. To illustrate, an example of a CVXGEN code is:

dimensions
  n = 10  
end

parameters
  Q (n,n) psd  # quadratic penalty.
end

variables
  x (n)
end

minimize
  quad(x, Q)
end​​​​​​​​​​​​​

​This code is inputted at cvxgen.com. On this website, I can then generate the C code which gives me a unique number. I can then compile this into MEX code using the unique number. Last, I can call this MEX code (csolve) from MatLab by running the following code

n=10; % dimension of the problem
params.Q = eye(n,n); % assume that the Hessian is the identity
[vars, status] = csolve(params); % this outputs optimal x* = 0.

This procedure, however, requires for each dimension of the problem n that I want to run, I need to go to cvxgen.com, change n, compile code, then run my MatLab code. Is it possible to let n enter as a parameter? This way, I only need to compile the code once, then in my MatLab code set params.n = n and params.Q = eye(n,n), and then call [vars, status] = csolve(params);.

Amir
  • 10,600
  • 9
  • 48
  • 75

1 Answers1

0

In short, I do not think it is possible to specify arbitrary dimension on cvxgen.com. I do have one solution: First, in MatLab, allow the user to specify his/her email address and password for cvxgen.com. Next, using system command in MatLab, call a python or javascript program that executes the following steps:

1) Log user into cvxgen.com

2) Goto edit tab on website

3) Copy and paste the cvxgen code

4) Goto generate c tab

5) Click generate code

6) Goto matlab tab

7) Copy unique identifying number for the compiled C code to be downloaded

8) Pass the unique identifying number back to MatLab and compile the Mex files in MatLab by calling the identifying number.

Now the Mex files can be called in MatLab by the following commands:

n=10; % dimension of the problem
params.Q = eye(n,n); % assume that the Hessian is the identity
[vars, status] = csolve(params); % this outputs optimal x* = 0.