Inverting a Matrix

Copyright Kevin G. TeBeest
file: linsolve.mws

First load the "linalg" package for doing linear algebra:

> with(linalg):

Example: Define a 4 x 4 matrix A:

> A := matrix( [ [ 2, 8, –10, 4 ], [ 4, 13, –38, –1 ], [ 5, 22, –7, –26 ], [ 4, 19, 0, 0 ] ] ) ;

[Maple Math]

Calculate the determinant of A.

> det( A ) ;

[Maple Math]

Since the determinant is not zero, A has an inverse.

Calculate the inverse of A, and call it Ainv:

> Ainv := inverse( A ) ;

[Maple Math]

Convert the inverse to decimal form:

> evalf( evalm( Ainv ) ) ;

[Maple Math]

Define a constant vetor b:

> b := vector( [ 16, –22, 46, 73 ] ) ;

[Maple Math]

We may solve the linear system Ax = b by using the formula x = A–1b :

> x := multiply( Ainv, b ) ;

x := [4, 3, 2, 1]

Let's check: let's now solve the same system Ax = b using the "linsolve" command:

> x := linsolve( A, b ) ;

x := [4, 3, 2, 1]


Return to Section 2.3

Return to Section 2.3(b)