% This m-file computes the inverse of a 3x3 matrix
% by row reduction.
% Use must hit any key to get the next stage of 
% of the computation





format short

echo on

% Enter the matrix to be inverted
%

M=[2 2 4;1 0 1;0 1 0]

% Then form augmented matrix
%

I=eye(3);


A = [M I]


% Next row reduce so left block  become the identity.
%
% Interchange first two rows.
%

pause

A([1 2], :) = A([2,1],:)


% Interchange last to rows
%

pause


A([2 3], :) = A([3,2],:)

% Use the ones in first two columns to eliminate.
%
% Subtract twice first from third
% 

pause

A(3,:) = A(3,:)-2*A(1,:)

% Subtract twice second from third
%

pause

A(3,:) = A(3,:) - 2*A(2,:)

% Divide third by 2
%

pause

A(3,:)=A(3,:)/2

% Subract third from first to complete reduction.
% 

pause

A(1,:) = A(1,:) - A(3, :)

pause

% Let B equal the computed inverse
%

B= A(:,[4 5 6])

pause

% Check the comutation
%

B*M

echo off