YoungPC
(Pengcheng Yang)
December 21, 2022, 4:24am
1
I am doing a test on a simple convex problem, but the CVX told me “Inner matrix dimensions must agree.”
The code is listed as follows, where x_test is a known 1000 * 1 vector.
cvx_begin
variable z(1000,1) complex
minimize z’*z-real(z’ * x_test)
subject to
norm(z,inf)<=1
cvx_end
YoungPC
(Pengcheng Yang)
December 21, 2022, 4:38am
3
I have modified the code in the ‘minimize’ line as:
minimize real(z’*z) - real(z’*x_test)
and the code ran successfully.
But I’m wondering if the result is correct?
Use parentheses around the entirety of the objective function. Due to a quirk in CVX or MATLAB (I guess it could be called a feature), it is good practice to always do that when the objective has more than one term, although might not always be necessary.
The following executes successfully.
x_test = rand(1000,1);;
cvx_begin
variable z(1000,1) complex
minimize (z'*z-real(z' * x_test))
subject to
norm(z,inf)<=1
cvx_end
If minimize z'*z-real(z' * x_test)
is used instead, the error message is generated.
Error using * (line 41)
Inner matrix dimensions must agree.
Error in minimize (line 14)
x = evalin( 'caller', sprintf( '%s ', varargin{:} ) );
YoungPC
(Pengcheng Yang)
December 21, 2022, 6:52am
6
Thanks a lot!
My problem has been solved by your method.