% Matlab diary from cs111, Oct 10 2007. % % This is what I typed in class. % % Type it into Matlab yourself to % reproduce the output I showed. A = rand(7) A = rand(7)-.5 A = 100*(rand(7)-.5) A = round(100*(rand(7)-.5)) lugui(A) P = eye(5) P(2,2) P(1, :) P(1, [1 2 3 4 5]) P(1, 1:5) 1:5 P P([2 3 4 5],:) P = [ P([2 3 4 5],:) ; P(1,:) ] A P * A A = round(100*(rand(5)-.5)) clc A P P * A P*P Q = P*P A Q*A P ^ 5 P * P^4 P^4 inv(P) P P' P inv(P) clc A P*A A*P P * A * P' A help lu [L, U, P] = lu(A) A L * U P * A P*A - L*U b = [ 1 ; 2 ; 3 ; 4 ; 5] c = P*b L U A [L, U, P] = lu(A) b c = P*b y = L \ c x = U \ y A * x ans-b residual = b - A*x x norm(x) norm(residual) A = [10^-20 1 ; 1 1] A(1,1) b = [1 ; 2] x = A \ b residual = b - A*x [L, U, P] = lu(A) x = U \ ( L \ ( P * b)) A\b [L,U] = lugui(A) % and then select "diagonal pivoting" L(2,1) U(2,2) U(1,1) x = U \ ( L \ b) L*U A clc help lutx A A = round(100*(rand(5)-.5)) [L,U,P] = lu(A) [LL,UU,pp] = lutx(A) P * [1;2;3;4;5] P pp L - LL U - UU help lutx A pp A(pp,:) P*A edit lutx edit bslashtx