www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/CompareMatrixLogarithmsExample.m

    %% Compare Matrix Logarithms
% Calculate the matrix exponential of a matrix, |A|.

% Copyright 2015 The MathWorks, Inc.

A = [1 1 0; 0 0 2; 0 0 -1];
Y = expm(A)

%%
% Calculate the matrix logarithm of |Y| to reproduce the original matrix,
% |A|.
P = logm(Y)

%%
% |log(A)| involves taking the logarithm of zero, so it produces inferior
% results.
Q = log(A)