function [C] = MatPower(A,n)
p=size(A);
l=p(1,1);
m=1;
remainder=0;
B=A;
C=diag(ones(1,l));
while (remainder ~= n)
   x = rem((n-remainder)/m,2);
   remainder = remainder + x*m;
   if (x ~= 0) C = B*C;end
   if (remainder ~= n)
      B = B*B;m=2*m;
   end
end
