%% command for n x n identity matrix is eye(n)
eye(1)
eye(2)
eye(3)

%% command for finding inverse is inv
A=[3 5; 2 4]
B=inv(A)
A*B
B*A

%% doesn't work for singular matrices
inv([1 0; 0 0])

%% the algorithm for finding inverses is to use rref on [A eye(n)]
AA=[A eye(2)]
rref(AA)
BB=ans(1:2,3:4)
BB*A
A*BB

%% larger example
C=[1 2 4 -10; 7 0 3 6; -5 -7 11 2; .5 3 17 -2]
[C eye(4)]
rref(ans)
D=ans(1:4,5:8)
C*D
D*C
%% can get the same thing just by using the inverse command
inv(C)
D

%% using inverses to solve systems
%% the unique solution to Cx=u is x=inv(C)*u
u=[-3 4 5 6]' %% ' is transpose command
x=inv(C)*u
%% check that it works
C*x

%% challenge problem!
%% E is a 3 x 4 matrix
%% Can you find a 4 x 3 matrix F so that EF=eye(3) ?
E=[ 10 -3 3 7; 10 -7 5 6; 11 -4 -7 19]


