matlabmathematical-optimizationconvex-optimizationcvx

How do I resolve the “Inner matrix dimensions must agree” error?


This is my code in CVX:

load('C')

r=C(:,4);
t=C(:,5);

n = size(C,1);
N = 100;

for i=1:n
    eta(i,1) = randn()/2;
end

cvx_begin
    variable x(n,1)

    maximize r'*x - t'*x

    subject to
        ones(n,1)'*x == N
        x >= zeros(n,1)
        exp(-x/N) >= eta
cvx_end

It gives the following error in the line where the objective function is declared:

“Inner matrix dimensions must agree.”

What am I doing wrong?

The error persists even if I write the last constraint as follows:

for i=1:n
    exp(-x(i,1)/N) >= eta(i,1)
end

Solution

  • The error is that I did not put parentheses around the objective function, which is required in this particular case as it has 2 terms. So, maximize (r'*x-t'*x) solves the error.