function p6
%t2
t3


function t1
A= [1 1; 4 1];   disp_eig(A)
A= [0 1; -1 -3]; disp_eig(A)
A= [0 1; 1 0];   disp_eig(A)


function disp_eig(A)
[V,D]= eig(A);

eigvalues= diag(D)'

% make easy to read eigenvectors
% enforce first coord of eigenvectors = 1 (NOT always possible!)
V= V./repmat(V(1,:),2,1)

% for my eyes: eig works very well; very small numeric errors have
% always to exist as computers have high, but limited, precision!
% B= (V)*D*inv(V); err= max(max(abs(B-A)))
return


function t2
%s= tf([1 0],1);
syms s
B= [s-1 1; 4 s-1]/((s-1)*(s-1)-4);
%pretty(simplify(ilaplace(B)))
pretty(ilaplace(B))


function t3
syms s
lst= {[1 1; 4 1], [0 1; -1 -3], [0 1; 1 0]}; N= length(lst);
Vsav= [];
Dsav= [];

figure(201); clf
for i=1:N
    fprintf(1, '====================================== case %d:\nexp(At)=\n\n', i);
    A= lst{i};
    [V,D]= eig(A);
    Vsav= [Vsav V./repmat(V(1,:),2,1)];
    Dsav= [Dsav [D(1,1); D(2,2)]];

    % compute exp(A*t)
    I   = eye(size(A,1));
    eAt = ilaplace(inv(s*I-A));

    % display using text
    pretty(eAt)

    % display using LaTeX
    text(0,1-(i-1)/N,['$$ A=' latex(sym(lst{i})) ' \quad\rightarrow\quad ' ...
        'e^{At}=' latex(eAt) '$$'], 'Interpreter','latex','FontSize',15)
    axis off
end

fprintf(1, '\n====================================== Summary:\n', i);
Dsav
Vsav
