# Inner matrix dimensions must agree.12-28

When I ran my program, the error occurred as followed:

the followling is my code:

function [return_W, trace_W] = CVX_bernstein_inequality1(alpha_k,beta_k, IN, IL,P1, P2, h1, h2, sigma_k, hd, NT, Rs_2,A,Q1,Q2,g1,g2)
% Rs_2=2;
cvx_clear
cvx_begin SDP quiet %
variable a_1 nonnegative
variable a_2 nonnegative
variable b_1 nonnegative
variable b_2 nonnegative
variable W(NT, NT) complex semidefinite

``````minimize (real(trace(W))); % 目标函数
subject to % 以下为制约条件

Lambda_1 =blkdiag(alpha_k(1)^2*sqrt(IN - P1)*W*sqrt(IN - P1),(-1)*(Rs_2 * (1 + (hd' * W * hd)) - 1)*beta_k(1)^2*A*sqrt(IL - Q1) );
Lambda_2 =blkdiag(alpha_k(2)^2*sqrt(IN - P2)*W*sqrt(IN - P2), (-1)*(Rs_2 * (1 + (hd' * W * hd)) - 1)*beta_k(2)^2*A*sqrt(IL - Q2) );

c1 = (real(Rs_2 * (1 + (hd' * W * hd)) - 1 - real(h1' * W * h1)+real(Rs_2 * (1 + (hd' * W * hd)) - 1 ).*real(g1' * W * g1)));
c2 = (real(Rs_2 * (1 + (hd' * W * hd)) - 1 - real(h2' * W * h2)+real(Rs_2 * (1 + (hd' * W * hd)) - 1 ).*real(g2' * W * g2)));

a1 =blkdiag(alpha_k(1)*sqrt(IN - P1) *W*h1  ,(-1)*(Rs_2 * (1 + (hd' * W * hd)) - 1)*beta_k(1)*sqrt(IL - Q1)*A*g1);
a2 =blkdiag(alpha_k(2)*sqrt(IN - P2) *W*h2 ,(-1)*(Rs_2 * (1 + (hd' * W * hd)) - 1)*beta_k(2)*sqrt(IL - Q2)*A*g2);

%约束1
trace(Lambda_1) + sqrt(2 * sigma_k) * a_1 + sigma_k * b_1 - c1 <= 0;
trace(Lambda_2) + sqrt(2 * sigma_k) * a_2 + sigma_k * b_2 - c2 <= 0;
%约束2
real(norm([vec(Lambda_1); sqrt(2) * a1])) <= a_1;
real(norm([vec(Lambda_2); sqrt(2) * a2])) <= a_2;
%约束3
b_1 * IN - Lambda_1 >= 0;
b_1 >= 0;
b_2 * IN - Lambda_2 >= 0;
b_2 >= 0;
W >= 0;
%     Rs_2>0;
cvx_end
return_W = W;
trace_W = (real(trace(W)));
``````

end

Use `whos` to see the dimensions of everything, and determine which are non-conformal, i.e., not dimensionally compatible. Note that CVX does not support implicit expansion for any CVX variables or expressions.