% P2
% Explores properties of n-by-n pascal matrix system and the solution
% when lu is used.
clc
for n=4:4:16
    % Set up and solve...
    A = pascal(n); [L,U,P] = lu(A); b = A*ones(n,1);x = U\(L\(P*b));
    % Properties...
    kappa = cond(A,1);
    relerr = norm(x - ones(n,1),1)/n;
    relerrEst = eps*kappa;
    fprintf('\nn = %2d\ncond =      %10.2e\nrelerr =    %10.2e\nrelerrEst = %10.2e\n',...
        n,kappa,relerr,relerrEst)
    format long
    x = x
end

% Let G be the Pascal triangle matrix. Note, P(n) = G*G'.
% Subtract 1 from the (n,n) entry of P(n) and let Ptilde be the result.
% Subtract 1 from the (n,n) entry of G and let Gtilde be the result.
% Note that Ptilde = Gtilde and det(Gtilde) = 0.