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);
.