%
% Script file: M3x3.m
% Generate a 3 by 3 matrix A with integer elements in [ 0, 20],
%      and a 3 by 1 column vector b whose elements in [-10,10],
%
A=randi([0,20],3,3);
b=randi([-10,10],3,1);
%
% Practice Matlab commands to do fundamental Questions of Linear Algebra
% (a) solve Ax=b
% (b) det(A)
% (c) rank(A)
% (d) norm(A,1), norm(A,2), norm(A,inf)
% (e) poly(A)
% (f) [V,D]=eig(A)
% (g) [U,S,V]=svd(A)
% (h) [W L]eig(A'*A)
% (i) [Q R]=qr(A)
% (j) y=R\(Q'*b)
% (k) norm(x-y,2)
%
'[A|b]=', [A,b]
x=A\b                                    % Solve Ax=bM3x3
'[det(A), rank(A)]=', [det(A), rank(A)]  % det(A), rank(A)
'[1-norm, 2-norm, inf-norm]=', [norm(A,1), norm(A,2), norm(A,inf)]
% norm(A,1), norm(A,2), norm(A,inf)
poly(A)
[V D]=eig(A)
[U S V]=svd(A)
[W L]=eig(A'*A)
[Q R]=qr(A)
y=R\(Q'*b)
norm(x-y,2)