# CVX Not Running Quadratic Optimisation

Hello,

I’m trying to implement a simple quadratic optimisation my lecturer set me and there is an issue with my system which has completely stumped him so I would appreciate any assistance this forum can offer.

I am trying to implement this system:

This is my MATLAB (run with R2020b) code:
% Solving Least Squares Problem
clear all;
clc;

% Generate data
n = 10;
m = n;
P = randn(n);
P = P*P’;
q = randn(n,1);
r = randn;
G = randn(m,n);
h = randn(m,1);
A = randn(n,n);
b = randn(n,1);

% Create and solve problem
cvx_begin
variable x(n)
dual variables y1 y2
minimize(0.5x’Px + q’x +r)
subject to
y1 : G
x <= h;
y2 : A
x == b;
cvx_end

x

This is the error I’m getting:
Check for missing argument or incorrect argument data type in call to function ‘vec’.

v = vec( v );

Error in * (line 261)
[ z2, success ] = quad_form( xx, P, Q, R );

minimize( 0.5*x’Px + q’*x + r );

I have installed CVX correctly as it runs for a least squares example program. However, it is highlighting that there is something wrong in the vec() function.

I would appreciate any guidance/support you can offer and if you need anymore information then please tell me and I’ll make sure to add it to the original post.

Josh

Your program runs without error for me, although the chances of your random inputs being feasible may not be very high,

Are you using CVX 2.2.? If not,switch to that. Otherwise, perhaps there is a conflict with a different version of vec in your MATLAB path.

Look at the output of
which -all vec

Hi Mark,

Many thanks for your suggestions. I have checked my CVX version and it’s 2.2. I did have multiple vec.m because I had YALMIP installed for a previous project. I have removed it from the path and the same error occurs despite restarting MATLAB and verifying the number of vec() functions:

which -all vec
D:\cvx-w64\cvx\functions\vec_\vec.m
D:\cvx-w64\cvx\functions@cvx\vec.m % cvx method

Nevermind Mark, it now runs without any issues.

Thank you very much, you have no idea how grateful I am!

What did the problem turn out to be? I.e., how did you get it to no longer be a problem?

I seemed to be the multiple vec()s you suggested. I’ve no clue why it didn’t initially work but after leaving it for 10 mins, it seemed to sort itself out. It’s not the handiest solution but I removed YALMIP from the path, left it and it now works.

Try putting YALMIP in the MATLAB path after CVX.

If you do so, I suggest removing geomean.m and logdet.m from the CVX installation; Because if you do not, those CVX files redirect to geo_mean and log_det. Which means that if YALMIP calls geomean and logdet, that would be converted into call to CVX’s geo_mean and log_det, and that would not end nicely. After removing geomean.m and logdet.m, you will still have geo_mean and log_det, which is what you actually need in CVX.

If you do all this, as far as I know, CVX and YALMIP should coexist and both work properly and completely.

And yes, i learned all this the hard way.