MatrixInverse.mw

Math 22 Fall 2004

Linear Algebra with Applications


The Inverse of a Matrix

October 11, 2004

    Load the packages for doing  Linear Algebra

> with(Student[LinearAlgebra]):

Warning, the protected name `.` has been redefined and unprotected

   Define a matrix we want to invert

> A := <<0, 3, -1>|<2, -2, 0>|<1, -5, 1>>;

A := Matrix([[0, 2, 1], [3, -2, -5], [-1, 0, 1]])

   Augment it with the identical matrix

> A_I := <A | IdentityMatrix(3)>;

A_I := Matrix([[0, 2, 1, 1, 0, 0], [3, -2, -5, 0, 1, 0], [-1, 0, 1, 0, 0, 1]])

    Perform row reductions to transform A into

    the Reduced Echelon Form (that is, the identity matrix).

> A_I := SwapRows(A_I, 1, 3);

A_I := Matrix([[-1, 0, 1, 0, 0, 1], [3, -2, -5, 0, 1, 0], [0, 2, 1, 1, 0, 0]])

> A_I := AddRow(A_I, 2, 1, 3);

A_I := Matrix([[-1, 0, 1, 0, 0, 1], [0, -2, -2, 0, 1, 3], [0, 2, 1, 1, 0, 0]])

> A_I := AddRow(A_I, 3, 2, 1);

A_I := Matrix([[-1, 0, 1, 0, 0, 1], [0, -2, -2, 0, 1, 3], [0, 0, -1, 1, 1, 3]])

> A_I := MultiplyRow(A_I, 3, -1):
A_I := MultiplyRow(A_I, 2, -1/2):

A_I := MultiplyRow(A_I, 1, -1);

A_I := Matrix([[1, 0, -1, 0, 0, -1], [0, 1, 1, 0, (-1)/2, (-3)/2], [0, 0, 1, -1, -1, -3]])

> A_I := AddRow(A_I, 2, 3, -1):
A_I := AddRow(A_I, 1, 3, 1);

A_I := Matrix([[1, 0, 0, -1, -1, -4], [0, 1, 0, 1, 1/2, 3/2], [0, 0, 1, -1, -1, -3]])

    Now the last 3 columns should form the inverse matrix of A

> A_Inverse := LinearAlgebra[DeleteColumn](A_I, [1 .. 3]);

A_Inverse := Matrix([[-1, -1, -4], [1, 1/2, 3/2], [-1, -1, -3]])

      Let's check our answer

> A.A_Inverse, A_Inverse.A;

Matrix([[1, 0, 0], [0, 1, 0], [0, 0, 1]]), Matrix([[1, 0, 0], [0, 1, 0], [0, 0, 1]])

>