%% Sensitivity of Badly Conditioned Matrix
% Examine the sensitivity of a badly conditioned matrix.
% A notable matrix that is symmetric and positive definite, but badly conditioned, is the Hilbert matrix. The elements of the Hilbert matrix are H(i,j) = 1/(i + j -1).
% Create a 10-by-10 Hilbert matrix.

A = hilb(10);

%
% Find the reciprocal condition number of the matrix.

C = rcond(A)

% The reciprocal condition number is small, so A is badly conditioned.
%
% The condition of A has an effect on the solutions of similar linear systems of equations. To see this, compare the solution of Ax = b to that of the perturbed system, Ax = b + 0.01.
% Create a column vector of ones and solve Ax = b.

b = ones(10,1);
x = A\b;

%
% Now change b by 0.01 and solve the perturbed system.

b1 = b + 0.01;
x1 = A\b1;

%
% Compare the solutions, x and x1.

norm(x-x1)

% Since A is badly conditioned, a small change in b produces a very large change (on the order of 1e5) in the solution to x = A\b. The system is sensitive to perturbations.
% Copyright 2012 The MathWorks, Inc.