InClass3.4-Inverses.mws

3.4 Inverses

In-class demo by Russell Blyth.

> restart: with(linalg):

Warning, the protected names norm and trace have been redefined and unprotected

We start with a random 3 x 3 matrix.

> A:= randmatrix(3,3,entries=rand(-3..3));

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

Find the inverse of the matrix A. The equation Y = AX computes Y given X. We need to compute X given Y. Define a general Y, and solve for X:

> Y := vector(3,[y1,y2,y3]);
AugA := augment(A,Y);
RedA := gaussjord(AugA);

Y := vector([y1, y2, y3])

AugA := matrix([[3, 0, 1, y1], [3, 1, -1, y2], [2, ...

RedA := matrix([[1, 0, 0, 1/5*y1+1/5*y3], [0, 1, 0,...

Let's extract the expression for X in terms of Y

> Xvec := delcols(RedA,1..3);

Xvec := matrix([[1/5*y1+1/5*y3], [y2-1/5*y1-6/5*y3]...

> y1vec := subs(y1=1,y2=0,y3=0,op(Xvec));
y2vec := subs(y1=0,y2=1,y3=0,op(Xvec));
y3vec := subs(y1=0,y2=0,y3=1,op(Xvec));

y1vec := matrix([[1/5], [-1/5], [2/5]])

y2vec := matrix([[0], [1], [0]])

y3vec := matrix([[1/5], [-6/5], [-3/5]])

Thus Xvec = y1*y1vec + y2*y2vec + y3*y3vec. If we make a matrix with y1vec, y2vec, y3vec as the columns, then y1, y2 and y3 are the coefficients of the linear combination giving X. We write this as BY, where

> B := augment(y1vec,y2vec,y3vec);

B := matrix([[1/5, 0, 1/5], [-1/5, 1, -6/5], [2/5, ...

Check:

> evalm(B&*Y);

vector([1/5*y1+1/5*y3, y2-1/5*y1-6/5*y3, -3/5*y3+2/...

This is just the transpose of Xvec. Thus X = BY. B is the inverse of A!

Check the products AB and BA:

> evalm(A&*B);
evalm(B&*A);

matrix([[1, 0, 0], [0, 1, 0], [0, 0, 1]])

matrix([[1, 0, 0], [0, 1, 0], [0, 0, 1]])

Note the first column of B arises from solving AX = [1, 0, 0]^t ; the second column from solving AX = [0, 1, 0]^t and the third column from solving AX = [0, 0, 1]^t . These three systems may be solved simultaneously, by finding the reduced row echelon form of the matrix [A,I]

> I3 := array(identity,1..3,1..3);
BigA := augment(A,I3);
RedBigA := gaussjord(BigA);

I3 := array(identity,1 .. 3,1 .. 3,[])

BigA := matrix([[3, 0, 1, 1, 0, 0], [3, 1, -1, 0, 1...

RedBigA := matrix([[1, 0, 0, 1/5, 0, 1/5], [0, 1, 0...

Note the final three columns are precisely the inverse matrix B.

Maple has a built-in inverse command:

> inverse(A);

matrix([[1/5, 0, 1/5], [-1/5, 1, -6/5], [2/5, 0, -3...

>

>