Why a simple problem is failed? Error: Inner matrix dimensions must agree

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

image

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{:} ) );

Thanks a lot!
My problem has been solved by your method.