% Rank-1 Updating Solution: Eg 2.19 Heath, p.82
% rank1update.m
% K. Ming Leung, 02/03/03

clear all; format short;
A = [1 2 2; 4 4 2; 4 6 4];
b = [3; 6; 10]; u = [0; 0; 1]; v = [0; 2; 0];
% A' = A-u*v.'  the actual matrix of interest

% Compute the LU factorization of A:
[L,U] = LU_factor(A,3);
% Solve Az = u
xx = forwardSubstitution(L,u,3);
z = backSubstitution(U,xx,3),
% Solve Ay = b
xx = forwardSubstitution(L,b,3);
y = backSubstitution(U,xx,3),
% Compute the solution using Sherman-Morrison formula
vy = v.'*y;
vz = v.'*z;
x = y + (vy/(1-vz))*z,

% Compute the solution using Matlab's linear equation
% solver
xMatlab = (A-u*v.')\b,
