Tuesday, March 12, 2013

Matlab: The Four Subspaces and the Fundamental Theorem of Linear Algebra

Understanding the four fundamental subspaces of a matrix is central to looking at soul of a general matrix. Here is a short essay by Gilbert Strang which outlines them.

It is very easy to write a Matlab or GNU Octave program that demonstrates the different parts of the theorem for a general matrix. Here is one  (fundaspace.m).

It takes as input any matrix, and demonstrates the dimension, bases and orthogonality of the four spaces. When called without any arguments it demonstrates the following example.

octave> fundaspace()

GIVEN MATRIX A

    1    2    3    4
    5    6    7    8
    9   10   11   12

Number of Rows, m = 3
Number of Cols, n = 4

Rank, r = 2

FOUR SUBSPACES

Column Space Basis
    1    2
    5    6
    9   10

Left Null Space Basis
   0.40825
  -0.81650
   0.40825

Row Space Basis
   1   5
   2   6
   3   7
   4   8

Null Space Basis
   0.044995  -0.545871
   0.346875   0.761366
  -0.828735   0.114882
   0.436865  -0.330377


FUNDAMENTAL THEOREM: Dimension

dim(ColSpace) + dim(Left NullSpace) = m, (2 + 1 = 3)
dim(RowSpace) + dim(NullSpace) = n, (2 + 2 = 4)

FUNDAMENTAL THEOREM: Orthogonality

ColSpace' * Left NullSpace

  -2.2204e-16
  -8.8818e-16

RowSpace' * NullSpace

  -8.3267e-17   5.5511e-16
   2.7756e-17   5.5511e-16



No comments: