How to solve this trace maximization problem

H=randn(8,2,10);


cvx_begin 

variable W(8,8,10);
expression M 
expression N
   
for m=1:1:2
    M=M+H(:,:,m)'*W(:,:,m)*H(:,:,m);    
end

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

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

subject to

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

for i = 1:10
    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.

 Error in maximize (line 20)
 arg = evalin( 'caller', sprintf( '%s ', varargin{:} ) );

 Error in test (line 21)
 maximize trace(N^(-1)*M)

If I change the optimization as

 maximize trace(M*N)

Then the error looks like

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

 Error in maximize (line 20)
 arg = evalin( 'caller', sprintf( '%s ', varargin{:} ) );

 Error in test (line 21)
 maximize trace(N*M)

How Can I get rid of this problem when my optimization is

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

If N is an invertible matrix then you should try computing its inverse with inv() before formulating the problem. If it is not, then you might see if the trace(inv(A)*B) can be decomposed in any favorable way, eventually depending on the properties of A.
Since we don’t know much on your matrices or the original problem it’s hard to tell.

Also, check the sizes since the second error appears to be due to the fact that trace yields a nonscalar result.

Also, I am following the paper ‘‘Convex Optimization for Precoder Design in MIMO Interference Networks’’ by Yue Zhao…Eq (20), the second part (trace part), though my problem is not the exactly the same.