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 :
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] ] ) ;
Solve the augmented matrix with the gaussjord command:
> soln := gaussjord( C ) ;
As long as the first n x n portion is the identity matrix, then the last column represents the solution
Store the solution (the 4th column of "soln") in vector xvec :
> xvec := col( soln, 4 ) ;
You may then reference the entries of the solution using their subscripts:
> xvec[1] ;
> xvec[2] ;
> xvec[3] ;
To convert the solution vector to decimal form, use:
> evalf( evalm (xvec) ) ;
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:
Note: in the above problem, the coefficient matrix A and the constant vector b are:
Define the coefficient matrix and the constant vector .
> A := matrix( [ [ 4, –2, 2], [ 20, –12, 3 ], [ –16, 14, 7 ] ] ) ;
> b := vector( [ -6, -52, 66 ] ) ;
Use linsolve to solve the system Ax = b , and name the solution vector xvec:
> xvec := linsolve( A, b ) ;
To convert the soution vector to decimal form, use:
> evalf( evalm( xvec ) ) ;
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.