How to solve this trace minimization problem

U=randn(2,2,4);
H=randn(2,8,4);


cvx_begin 
variable W(8,8,4);
expression M 
expression N



for m=1:2
    M=M+U(:,:,m)'*H(:,:,m)*W(:,:,m)*H(:,:,m)'*U(:,:,m);    
end

for n=3:4
    N=N+U(:,:,n)'*H(:,:,n)*W(:,:,n)*H(:,:,n)'*U(:,:,n);
end

maximize trace(M^(-1)*N)

subject to

norm(vec(W)) <= sqrt(P_tot); 

for i = 1:4
    W(:,:,i) == semidefinite(8);       
end
    
cvx_end

I get error like this

  Error using cvx/mpower (line 11)
  Disciplined convex programming error:
  Matrix powers not permitted.

If I change the optimization as

maximize trace(M*N)

Then I get

Error using cvx/mtimes (line 127)
Disciplined convex programming error:
Invalid quadratic form: must be a scalar.

How can I rectify this…