Matrix demensions not agree in CVX but okay outside

Hello guys, I met a new problem when I tried to do the calculation of a matrix calculation norm( (8x8x2).* (8x2) )calculation. for the (8x2) is the value that I want to acquire by CVX. However, when I input the equations, the program shows “Error using .* Matrix dimensions must agree.”

But when I move this out of the CVX (I set some default values for the desired matrix), it can calculate successfully.

The formula can be computed without any error, and I’ve checked that for wanted value matrix X and the test matrix has the same lengths.

So I wonder why does this problem happens and how should I do to let the CVX understands that the lengths are matched? Thank you!

CVX does not support implicit expansion MATLAB arithmetic expands in R2016b » Loren on the Art of MATLAB - MATLAB & Simulink .

You’ll need to use an appropriate combination of `repmat`, `reshape`, and `permute` in order to form an expression which does not rely on implicit expansion.

1 Like

Thank you Mark. The reason why I use this is because in my formulars I need to sqaured the X matrix in some parts of it, and I saw some other programes with similar equations and codes like shown below, and they can run successfully.

I’ll try to convert it. Thank you for your expaination!

`ones(1,2)+ones(2,1)` % relies on implicit expansion
ans =
2 2
2 2

`cvx_begin;variables x(1,2) y(2,1);x+y % implicit expansion not used in CVX`
Error using +
Matrix dimensions must agree.

1 Like

After adding a new loop to extract columns and calculate them with corrosponding matrices, the codes can now work. Thank you again.