Introduction to Linear Algebra

The following material was produced via the diary command of MATLAB.

>> % MATLAB is an excellent tool to manipulate matrices:
>> a = [1 2
        3 4]

a =

     1     2
     3     4

>> b = [5; 6]

b =

     5
     6

>> x = a\b  % solve the linear system a*x = b

x =

   -4.0000
    4.5000

>> b - a*x  % check the answer

ans =

     0
     0

>> % An important class of matrices are permutation matrices.
>> % A permutation matrix has exactly one 1 in every row and column,
>> % all other elements are zero.
>> x = [1 2 3 4]'   % turn row into column by transpose

x =

     1
     2
     3
     4

>> p12 = [0 1 0 0
          1 0 0 0
          0 0 1 0
          0 0 0 1]  % use to permute x(1) and x(2)

p12 =

     0     1     0     0
     1     0     0     0
     0     0     1     0
     0     0     0     1

>> y = p12*x

y =

     2
     1
     3
     4

>> p12*y

ans =

     1
     2
     3
     4

>> % so the inverse of p12 is again p12
>> % we call p12 a transposition matrix
>> % more complicated permutation matrices can be made by multiplying
>> % transposition matrices :
>> p13 = [0 0 1 0
          0 1 0 0
          1 0 0 0
          0 0 0 1]  % transposes x(1) and x(3)

p13 =

     0     0     1     0
     0     1     0     0
     1     0     0     0
     0     0     0     1

>> p13*x  % check

ans =

     3
     2
     1
     4

>> p123 = p12*p13

p123 =

     0     1     0     0
     0     0     1     0
     1     0     0     0
     0     0     0     1

>> p123*x

ans =

     2
     3
     1
     4

>> % Thus p123 first interchanges x(1) with x(3) and then interchanges
>> % x(1) with x(2); x(4) is left on its place.
>> % A theorem of algebra says that you can write every permutation
>> % matrix as a product of transposition matrices