%%
% norms of a vector
vec_2 = [1 -2 0 3];
norm(vec_2,inf) %maximum norm
norm(vec_2,1) %Manhattan (or taxicab, octahedron, L1) norm
norm(vec_2,2) %euclidean norm
norm(vec_2) %norm without second argument is euclidean norm
%properties of matrices
A = [4 -1 0; 2 3 -2; 0 -2 3];
sym_A = [4 2 0; 2 3 -2; 0 -2 3]; %symmetric matrix
%testing of symmetry
A-A' %test of matrix symmetry (result should be matrix of zeros)
isequal(A,A') %test of matrix symmetry (result should be 1 as true)
sym_A-sym_A' %test of matrix symmetry (result should be matrix of zeros)
isequal(sym_A,sym_A') %test of matrix symmetry (result should be 1 as true)
%testing of positive definitness of a matrix
det(A) %determinant of matrix A
det(A(1:2,1:2)) %determinant of submatrix (2x2 taken from the top left corner)
det(A(1,1)) %determinant of submatrix (1x1 taken from the top left corner)
%calculation of eigenvalues
eig(A) %eigenvalues of matrix A
max(abs(eig(A))) %spectral radius of matrix A
eig(sym_A) %eigenvalues of a symmetrix matrix are real, moreover this matrix is positively definite, i.e., eigen values are all positive
%norm of matrix
norm(A,inf) %row sum norm calculated by in-built function
max(sum(abs(A'))) %row sum calculated manually
norm(A,1) %column sum norm calculated by in-built function
max(sum(abs(A))) %column sum calculated manually
norm(A,'fro') %Frobenius norm by in-built function
sqrt(sum(diag(A'* A))) %Frobenius norm manually
norm(A,2) %spectral norm by in-built function
norm(A) %norm without second argument is spectral norm (norm generated by euclidean vector norm)
sqrt(max(abs(eig(A*A')))) %spectral norm calculated manually
%conditionality of a matrix
B = [2 6; 2 6.0001];
cond(B) %conditional number of matrix B - matrix B is badly conditioned
norm(B)*norm(inv(B)) %conditional number calculated manually
cond(sym_A) %conditional number of matrix A - matrix A is well conditioned
max(eig(sym_A))/min(eig(sym_A)) %positively definite matrix conditioned number is equal to maximum over minimum eigenvalue
norm(sym_A)*norm(inv(sym_A)) %conditional number calculated manually - spectral norm
norm(sym_A,inf)*norm(inv(sym_A),inf) %conditional number calculated manually - row sum norm,
norm(sym_A,1)*norm(inv(sym_A),1) %conditional number calculated manually - column sum norm,
norm(sym_A,'fro')*norm(inv(sym_A),'fro') %conditional number calculated manually - Frobenius norm,