echo on
%
% Script for problem 1, Assignment 1, AM261
% Feb 14-15, 2002
%
% RMC
%
% Question 1
S = [ 2 5 1 5
      5 7 2 6
      4 6 3 7
      5 7 4 8 ];
% (a) A matrix S is singular if det(S) = 0
det( S )
% Not zero, so the adding process is not necessary.
% (b) 
norm( S, 2 )
norm( S, 1 )
norm( S, inf )
% (c) if S = U Sig V', then Sx = b implies
% (U Sig V') x = b or
% U y1 = b, which can be solved by y1 = U' b
% Sig y2 = y1, which can be solved by y2 = diag(1/Sig(1,1), ..., 1/Sig(4,4) ) y1
% V' x = y2, which can be solved by x = V y2
[U, Sig, V] = svd( S )
b = [1,-1,1,-1]'
y1 = U'*b
SigInv = diag( [1/Sig(1,1), 1/Sig(2,2), 1/Sig(3,3), 1/Sig(4,4) ] )
y2 = SigInv*y1
x = V*y2
% (d) Residual
residual = b - S*x
r1 = norm(residual,1)
% (e) Condition numbers:
% We conclude that the computed solution has relative accuracy about
% k times the norm of the residual divided by the norm of b.
k2 = Sig(1,1)/Sig(4,4)
k1 = 1/rcond(S)
kinf = norm(S,inf)*norm(S^(-1),inf)
relative_accuracy = r1*k1/norm(b,1)