function ShowPosDef()
% Illconditioned positive definite matrices.

% The nxn hilbert matrix is symmetric and positive definite.
% cond(hilb(n)) is large for even modest values of n...
for n=2:8
% The (i,j) entry of the hilbert matrix is 1/(i+j-1) = integral from
% 0 to 1 of x^(i-1)*x^(j-1)
clc
format short
A = hilb(n)
fprintf('cond(A) = %10.3e\n',cond(A))
format long
The_Eigenvalues_of_A = eig(A)
pause(.2)
end
% Turns out that the inverse of a hilbert matrix is known exactly and
% invhilb(n) returns its value.
% Let's check out the quality of a solution to a Hilbert system,
clc
n = 10;
A = hilb(n);
b = randn(n,1);
% Conventional solve approach...
L = chol(A,'lower');
x = L'\(L\b);
% Solution via exacly known inverse...
xExact = invhilb(n)*b;
relErr = norm(x-xExact)/norm(xExact);
relErrEstimate = eps*cond(A);
fprintf('norm(x - xExact)/norm(xExact) = %10.3e\n',relErr)
fprintf('eps*cond(A) = %10.3e\n',relErrEstimate)