Matlab: Norms and other properties of matrices

>> M = [1  2.7 -3; 4  5  1]

Matrix (or vector) norms:

for every norm, there is a set of equivalent commands how to obtain it:

column norm
>> max(sum(abs(M)))
>> norm(M,1)  
row norm
>> max(sum(abs(M')))
>> norm(M,inf)
Frobenius norm:
>> sqrt(sum(diag(M'* M)))
>> sqrt(trace(M'* M))
>> norm(M,'fro')
spectral norm - max. singular value
>> max(sqrt(eig(M'* M)))
>> max(svd(M))
>> norm(M)     
>> norm(M,2) 

Properties of square matrices:

>> A = [0.5  1 ; -1  0 ]

determinant:

>> d = det(A)

trace of the matrix (sum of diagonal elements):

>> tr = sum(diag(A))
>> tr = trace(A)

eigenvalues and spectral radius:

>> lambda = eig(A)         % eigenvalues
>> alambda = abs(lambda)   % absolute values of eigenvalues
>> sp = max(alambda)       % spectral radius

>> sp = max(abs(eig(A)))   % all in one command

Matlab function for computation of spectral radius:

function sp = sp_rad(A)
  sp =  max(abs(eig(A)));
end 

eigenvalues graphically:

>> lambda = eig(A);                % eigenvalues
>> r = max(abs(lambda));           % computing spectral radius r
>> t = 0 : 0.2 : 2*pi+0.2 ;        % parameter for a circle
>> X = r*[sin(t);cos(t)];          % points on a circle with radius r
>> plot(X(1,:),X(2,:))             % plot the circle
>> hold on                         % continue on the same figure
>> plot(real(lambda),imag(lambda),'r*',0,0,'b+') % plot the eigenvalues
>> axis square;                    % the same scale on both axes
>> axis([ -r-1  r+1  -r-1  r+1 ])  % define span of axes - optional

checking if a matrix is symmetric: A = AT:

>> norm(A-A')       % = 0 (with reasonable precision)

checking if a symmetric matrix A is positive definite:
- we can check if all minors are positive (suitable for small matrices only):

>> A(1,1)           % > 0 
>> det(A(1:2,1:2))  % > 0
>> det(A(1:3,1:3))  % > 0
>> ...
>> det(A)           % > 0

- or (also for symmetric matrix) check if all eigenvalues are positive:

>> eig(A)           % > 0

rank:

>> h = rank(M)