%this is the actual demo file used in the demonstration
%you'd better look at the other file, unless you actually
%would like to prepare matlab demonstartions
!C
disp('we study in this demo various linear algebra topics')
disp('the first topic: how to measure the size of an error?')
disp('+++++++++++++++++++++++++++++++++++++++++++++')
pause

disp(' v=[-6 7 .5 -1] ')
v=[-6 7 .5 -1]
disp('+++++++++++++++++++++++++++++++++++++++++++++')
pause

disp(' norm(v,1) ')
norm(v,1)
disp('+++++++++++++++++++++++++++++++++++++++++++++')
pause
disp(' norm(v,2) ')
norm(v,2)
disp('+++++++++++++++++++++++++++++++++++++++++++++')
pause

!C
v
disp(' norm(v,inf) ')
norm(v,inf)
disp('+++++++++++++++++++++++++++++++++++++++++++++')
pause

disp(' norm(v,''fro'') ')
norm(v,'fro')
disp('+++++++++++++++++++++++++++++++++++++++++++++')
pause

!C
disp('Now, we compute matrix norms')


disp(' A=[-1 2 0; 3 -1 2] ')
A=[-1 2 0; 3 -1 2]
disp('+++++++++++++++++++++++++++++++++++++++++++++')
pause


disp(' norm(A,1) ')
norm(A,1)
disp('+++++++++++++++++++++++++++++++++++++++++++++')
pause

disp(' norm(A,2) ')
norm(A,2)
disp('+++++++++++++++++++++++++++++++++++++++++++++')
pause

!C
A
disp(' norm(A,inf) ')
norm(A,inf)
disp('+++++++++++++++++++++++++++++++++++++++++++++')
pause

disp(' norm(A,''fro'') ')
norm(A,'fro')
disp('+++++++++++++++++++++++++++++++++++++++++++++')
pause

disp('+++++++++++++++++++++++++++++++++++++++++++++')
disp('+++++++++++++++++++++++++++++++++++++++++++++')

!C
disp('Second topic: linear systems')
disp('first a warm-up')

disp(' A=[1 1; 2 -1] ')
A=[1 1; 2 -1]
disp('+++++++++++++++++++++++++++++++++++++++++++++')
pause


disp(' b=[7;8] ')
b=[7;8]
disp('+++++++++++++++++++++++++++++++++++++++++++++')
pause


disp(' x=A\b ')
x=A\b
disp('+++++++++++++++++++++++++++++++++++++++++++++')
pause


!C
disp(' clear all ')
clear all


disp('now a real example')

%disp(' A=[17 24 1 8 15; 23 5 7 14 16; 4 6 13 20 22; 10 12 19 21 3;11 18 25 2 9] ')
A=[17 24 1 8 15; 23 5 7 14 16; 4 6 13 20 22; 10 12 19 21 3;11 18 25 2 9]

disp('cond(A)')
cond(A)


disp(' [L, U, P]=lu(A); ')
[L, U, P]=lu(A);
disp('+++++++++++++++++++++++++++++++++++++++++++++')
pause

disp(' L ')
L
disp('+++++++++++++++++++++++++++++++++++++++++++++')
pause


disp(' U ')
U
disp('+++++++++++++++++++++++++++++++++++++++++++++')
pause


!C
disp(' A ')
A
disp(' PA=L*U ')
PA=L*U
disp(' L*U is a permuted version of A')

disp('+++++++++++++++++++++++++++++++++++++++++++++')
pause


disp(' P*A ')
P*A
disp('+++++++++++++++++++++++++++++++++++++++++++++')
disp('norm(PA-ans,2)')
pause
norm(PA-ans,2)
pause


disp(' b=[1 0 0 0 0]'' ')
b=[1 0 0 0 0]';
disp(' bp=P*b ')
bp=P*b
disp('+++++++++++++++++++++++++++++++++++++++++++++')
pause


!C
disp(' Now, we solve the system LUx=Pb')
disp(' y=L\bp ')
y=L\bp
disp('+++++++++++++++++++++++++++++++++++++++++++++')
pause


disp(' x=U\y ')
x=U\y
disp('+++++++++++++++++++++++++++++++++++++++++++++')
pause


disp(' x1=A\b ')
x1=A\b
disp('norm(x1-x,2)')
norm(x1-x,2)
disp('+++++++++++++++++++++++++++++++++++++++++++++')
disp('+++++++++++++++++++++++++++++++++++++++++++++')
pause



!C
disp('Another factorization is the the QR factroization')
disp(' [Q,R]=qr(A); ')
[Q,R]=qr(A);
disp('+++++++++++++++++++++++++++++++++++++++++++++')
pause

disp(' R ')
R
disp('+++++++++++++++++++++++++++++++++++++++++++++')
pause

disp(' A ')
A
disp(' Q*R ')
Q*R
disp('+++++++++++++++++++++++++++++++++++++++++++++')
pause

disp(' norm(A-Q*R,2) ')
norm(A-Q*R,2)
disp(' norm(A-Q*R,1) ')
norm(A-Q*R,1)
disp(' norm(A-Q*R,''fro'') ')
norm(A-Q*R,'fro')
disp('+++++++++++++++++++++++++++++++++++++++++++++')
pause

!C
disp(' Q ')
Q
disp('+++++++++++++++++++++++++++++++++++++++++++++')
pause
disp(' Q*Q'' ')
Q*Q'
disp('norm(eye(5)-ans,2)')
norm(eye(5)-ans,2)
disp('+++++++++++++++++++++++++++++++++++++++++++++')
disp('END OF DEMO') 





