%This file was prepared by Amos Ron on 26/08/97 as a short
%demonstation of  Matlab's lu and qr routines (for CS513).
%the file was used in class on 17/09/96 (lecture 6).

%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 demonstrations

%in order to prepare a similar demo (say, on another topic),
%run first a matlab session of your demo, and save the session in
%a diary. edit and clean the diary (a typical result is then the file
%`luqr' in this directory. You then convert the diary file into
%a demo file, by displaying each command in the .m file, by inserting
%pause commands at all appropriate location, by clearing the screen
%when necessary, etc.

disp('we examine the matlab routines `lu'' and `qr''')
disp('+++++++++++++++++++++++++++++++++++++++++++++')
pause

!C
disp('we first input a 3X3 matrix')
%we first input a 3X3 matrix
disp(' A=[2 4 2; 4 7 7; -2 -7 5]')
A=[2 4 2; 4 7 7; -2 -7 5]
pause


disp('the LU routine has one input argument, and three output arguments.')

disp(' [L,U,P]=lu(A)')
[L,U,P]=lu(A)
pause
!C

disp('the the first two arguments are the L-factor and the U-factor of the')
disp('matrix P*A. P*A obtained from A by permuting A''s rows. The actual')
disp('permutation is chosen on the run.')
disp(' L*U-P*A')
L*U-P*A
pause


disp('compared to the size of the original entries of A, 1e-15 must be considered')
disp('noise.')

disp(' L*U')
L*U
pause

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

disp(' [Q,R]=qr(A)')
[Q,R]=qr(A)
pause

disp('let''s check that Q is an orthogonal matrix:')
disp(' Q''*Q')
Q'*Q
pause


disp(' quit')
quit


