function F = MyExp(A)
% A is an n-by-n matrix
% F = T(A/m)^m where m is the smallest power of 2 so 
% norm(A/m,1)<=1 and T(C) = I + C + C^2/2! + ...+C^12/12!
[n,n] = size(A);

% Scaling...
alfa = norm(A,1);
t = max(0,ceil(log2(alfa)));
C = A/2^t;

% F = T(C)...

% -1 for this because it involves 11 mat-mat prods..
% C_power = C;
% F = eye(n,n) + C;
% for k=2:11
%    C_power = C*C_power/k;
%    F = F + C_power;
% end

% Can do it with 7... 
f = factorial(1:12);
I = eye(n,n);
C2 = C*C;
C3 = C2*C;
C4 = C2*C2;
C8 = C4*C4;
F = C8*(C4/f(12) + C3/f(11) + C2/f(10)+C/f(9) + I/f(8)) +...
    C4*(C3/f(7) + C2/f(6) + C/f(5) + I/f(4)) + ...
    C3/f(3) + C2/f(2) + C/f(1) + I;

% Actually, one student showed how to do it in 6 !

% F by repeated squaring. 
for j=1:t
    F = F*F;
end
% -2 for T^m or by repeated multiplication