Solving Linear Systems on Maple

Copyright 2002 Kevin G. TeBeest
file: linsolve.mws

Whenever performing matrix operations (linear algebra), first load the linalg library of commands:

> with( linalg ) :


1. Using the gaussjord command:

To define an augmented matrix C = matrix( [ [4, -2, 2, -6], [20, -12, 3, -52], [-16... :

Note: The above is an augmented matrix - the first 3 columns denote the coefficient matrix A , and the 4th column denotes the constant vector b .

> C := matrix( [ [ 4, –2, 2, –6], [ 20, –12, 3, –52], [ –16, 14, 7, 66] ] ) ;

C := matrix([[4, -2, 2, -6], [20, -12, 3, -52], [-1...

Solve the augmented matrix with the gaussjord command:

> soln := gaussjord( C ) ;

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

As long as the first n x n portion is the identity matrix, then the last column represents the solution x[1], x[2], x[3]

Store the solution (the 4th column of "soln") in vector xvec :

> xvec := col( soln, 4 ) ;

xvec := vector([-5, -3, 4])

You may then reference the entries of the solution using their subscripts:

> xvec[1] ;

-5

> xvec[2] ;

-3

> xvec[3] ;

4

To convert the solution vector to decimal form, use:

> evalf( evalm (xvec) ) ;

vector([-5., -3., 4.])

Alternatively, if you use decimal points on the entries of A , then all calculations will be done in decimal form.


2. Using the linsolve command:

To solve the matrix problem:    matrix([[4, -2, 2], [20, -12, 3], [-16, 14, 7]])*ma...

Note: in the above problem, the coefficient matrix A and the constant vector b are:

A = matrix([[4, -2, 2], [20, -12, 3], [-16, 14, 7]]...

Define the coefficient matrix   A = matrix([[4, -2, 2], [20, -12, 3], [-16, 14, 7]]... and the constant vector   b = matrix([[-6], [-52], [66]]).

> A := matrix( [ [ 4, –2, 2], [ 20, –12, 3 ], [ –16, 14, 7 ] ] ) ;

A := matrix([[4, -2, 2], [20, -12, 3], [-16, 14, 7]...

> b := vector( [ -6, -52, 66 ] ) ;

b := vector([-6, -52, 66])

Use linsolve to solve the system Ax = b , and name the solution vector xvec:

> xvec := linsolve( A, b ) ;

xvec := vector([-5, -3, 4])

To convert the soution vector to decimal form, use:

> evalf( evalm( xvec ) ) ;

vector([-5., -3., 4.])

Alternatively, if you use decimal points on the entries of A , then all calculations will be done in decimal form.


Copyright © 2002–2016 Kevin G. TeBeest. All rights reserved.