Javascript required
Skip to content Skip to sidebar Skip to footer

Find the Solution to the Syten Using Inverse Matrix

1303.mws


Module 13 : Linear Algebra

1303 : Matrix Methods

P U R P O S E

This module provides a whirlwind three days and two nights tour of most of the basic linear algebra methods including matrix methods of solving linear systems and matrix algebra. We will see the sights of how Maple can automatically solve both linear systems and matrix systems. And also see how we can perform some of the main techniques using Maple step by step. R E V I E W

Module 705 Linear Systems

Command Packages Needed :

> restart; with(linalg);

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

[BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp,...
[BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp,...
[BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp,...
[BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp,...
[BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp,...
[BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp,...
[BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp,...
[BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp,...

___________________________________________________________________________________

A. Solving Linear Systems

___________________________________________________________________________________

A linear system is a collection of first degree equations. A solution to a system consists of one or more sets of specific values that our common solutions to each of the individual equations. Here is a simple example which we can solve quite easily using the solve command.

> sys := { 3*x + 5*y + 2*z = 12, 2*x + 5*y - 4*z = 9,
4*x - y + 5*z = -3};

sys := {3*x+5*y+2*z = 12, 2*x+5*y-4*z = 9, 4*x-y+5*...

> solve( sys, {x,y,z});

{y = 99/37, z = 24/37, x = -33/37}

Remember, if you need to enter multiple lines at a single command prompt, type return (Macintosh) rather than enter, or shift-return (Window) rather than return.

Maple will automatically use fractions. However, you can force decimal answers using the evalf command.

> evalf(%);

{y = 2.675675676, z = .6486486486, x = -.8918918919...

AUTOMATIC MATRIX SOLUTION

We can also convert this system of equations to a matrix systems.

> A := genmatrix( sys, [x,y,z], b);

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

> evalm(b);

vector([12, 9, -3])

In this case, A is the coefficient matrix, and b is a vector representing the constant values. The command evalm(b) evaluates b as a matrix (a vector is an n 1 matrix). In other words, this command simply writes out what the vector b looks like.

A matrix method can be solved using a different command, the linsolve command.

> linsolve(A, b);

vector([-33/37, 99/37, 24/37])

This is useful if you start with a matrix equation to begin with, and so Maple

INVERSE MATRIX SOLUTION


Another way to solve a matrix equation Ax = b is to left multiply both sides by the inverse matrix A-1, if it exists, to get the solution x = A-1 b. We can do this just as well.

> inverse(A);

matrix([[-7/37, 9/37, 10/37], [26/111, -7/111, -16/...

> evalm( inverse(A) &* b);

vector([-33/37, 99/37, 24/37])

The evalm command forces a matrix computation and expresses the result.

DEPENDENT SYSTEMS


Some systems are dependent which means there are an infinite number of solutions. The form of these solutions will entail the use of parameters. Lets look at an example using two different methods : solve and linsolve.

> sys := { x + y -2*z = -4, x - 2*y + z = 3, 2*x -y -z = -1};

sys := {x+y-2*z = -4, x-2*y+z = 3, 2*x-y-z = -1}

> solve( sys, {x,y,z});

{y = -7/3+z, x = -5/3+z, z = z}

> A := genmatrix( sys, {x,y,z}, b);

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

> evalm(b);

vector([-4, 3, -1])

> linsolve(A, b);

vector([-5/3+_t[1], -7/3+_t[1], _t[1]])

In both cases, the solution contains a parameter. The solve command expresses it in terms of the actual variables used, and the linsolve command uses a funny _t character to distinguish it from a variable you might have defined yourself.

INCONSISTENT SYSTEMS


An inconsistent system has not solution. Maple generally, refuses to answer questions which have no answer.

> det(A);

0

> sys := { x + y + z = 8, x + y - 3*z = 10,
x + y - z = 1 };

sys := {x+y+z = 8, x+y-3*z = 10, x+y-z = 1}

> solve( sys, {x,y,z});

> A := genmatrix( sys, {x,y,z}, b);

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

> linsolve(A, b);

> evalm( inverse(A) &* b);

                              Error, (in inverse) singular matrix

Nothing seems to work, because nothing can work. There is no solution, and so Maple offers to do nothing!


In such case, det = 0.......

___________________________________________________________________________________

B. Gauss-Jordan Elimination

___________________________________________________________________________________


One of the most important methods used to solve a matrix system is Gauss-Jordan Elimination using row operations. The idea is this:-

Take an equation and obtain the coefficient matrix and constant vector as we did above.

> sys := [ 6*x - y - 5*z = 5, 3*x + 6*y + 2*z= 7 ,
4*x - 7*y - 7*z = 9 ] ;

sys := [6*x-y-5*z = 5, 3*x+6*y+2*z = 7, 4*x-7*y-7*z...

> A := genmatrix( sys, [x,y,z], b);

A := matrix([[6, -1, -5], [3, 6, 2], [4, -7, -7]])

> evalm(b);

vector([5, 7, 9])

Now create an augmented matrix by joining the coefficient matrix and constant vector into a single larger matrix. In this case, the 3x3 matrix A is combined with the 3x1 vector b to form a 3x4 augmented matrix

> A_b := augment(A, b);

A_b := matrix([[6, -1, -5, 5], [3, 6, 2, 7], [4, -7...

ROW OPERATIONS

The three row operations are
1. multiplying a constant times a row
2. adding one row to another (or adding a multiple of one row to another)
3. swapping two rows.
There is a Maple command for each of these : mulrow, addrow, and swaprow. The format of each of these commands if first the name of the matrix. In our case we will start with A_b, then use the % operator to refer to the most recent command at each step. If you mistype anything and need to re-execute a command, its best to go to the first of these commands (the evalm command) and then go through the whole process again, hitting enter on each line. Let's solve the system above using these three commands.

> evalm(A_b);

matrix([[6, -1, -5, 5], [3, 6, 2, 7], [4, -7, -7, 9...

First we add Row 2 to Row 3 because we can easily get a value of 1 in this way.

> addrow( A_b, 2, 3);

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

Next we swap rows 1 and 3 to get the 1 in the (1,1) position.

> swaprow( %, 1, 3);

matrix([[7, -1, -5, 16], [3, 6, 2, 7], [6, -1, -5, ...

Now we multiply 3*row 1 and add that to Row 2. And then add 2*Row 2 to Row 3. The optional third parameter of the addrow command is a value to multiply by the row being added to the other.

> addrow( %, 1, 2, 3);

matrix([[7, -1, -5, 16], [24, 3, -13, 55], [6, -1, ...

> addrow( %, 2, 3, 2);

matrix([[7, -1, -5, 16], [24, 3, -13, 55], [54, 5, ...

Now we multiply row 2 by -1/45 to get a 1 in the (2,2) position. And then add multiples of row 2 to rows 1 and 3 to zero the (1,2) and (3,2) positions.

> mulrow( %, 2, -1/45);

matrix([[7, -1, -5, 16], [-8/15, -1/15, 13/45, -11/...

> addrow( %, 2, 1, 13);

matrix([[1/15, -28/15, -56/45, 1/9], [-8/15, -1/15,...

> addrow( %, 2, 3, 13);

matrix([[1/15, -28/15, -56/45, 1/9], [-8/15, -1/15,...

Finally, we multiply row 3 by -45/28, and add multiples to complete the problem.

> mulrow( %, 3, -45/28);

matrix([[1/15, -28/15, -56/45, 1/9], [-8/15, -1/15,...

> addrow( %, 3, 2, -29/45);

matrix([[1/15, -28/15, -56/45, 1/9], [675/14, 59/14...

> addrow( %, 3, 1, 28/45);

matrix([[-47, -6, 26, -99], [675/14, 59/14, -391/14...

The answer is apparent in the last column.

We can speed thing up a little more by using the pivot command. This command performs several of the above steps at once. Let's bring back the original augmented matrix again, and get a 1 in the first row, first column.

> evalm( A_b);

matrix([[6, -1, -5, 5], [3, 6, 2, 7], [4, -7, -7, 9...


Now, instead of adding various multiples of row 1 to the other rows, simply pivot on that (1,1) position.

> mulrow( %, 1, 1/6);

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

> pivot( %, 1, 1);

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

Now get a 1 in the (2,2) position, and prvot on that position.

> mulrow( %, 2, -2/13);

matrix([[1, -1/6, -5/6, 5/6], [0, -1, -9/13, -9/13]...

> pivot( %, 2, 2);

matrix([[1, 0, -28/39, 37/39], [0, -1, -9/13, -9/13...

And finally pivot the (3,3) poition.

> pivot( %, 3, 3);

matrix([[1, 0, 0, 11], [0, -1, 0, 9], [0, 0, 28/39,...

AUTOMATIC REDUCTION


An even faster method is simply let Maple do all the work for us. The gausselim command will perform all of the steps of Gaussian elimination and reduce an augmented matrix to row echelon form.

> gausselim( A_b);

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

The two commands, gaussjord and rref, both do the same thing. They perform all of the steps of Gauss-Jordan elimination and reduce an augmented matrix into reduced row echelon form.

> gaussjord( A_b);

matrix([[1, 0, 0, 11], [0, 1, 0, -9], [0, 0, 1, 14]...

> rref( A_b);

matrix([[1, 0, 0, 11], [0, 1, 0, -9], [0, 0, 1, 14]...

This makes our lives easier but talkes all the fun out of it, don't you think?

___________________________________________________________________________________

C. Pure Matrix Operations

___________________________________________________________________________________

Matrices are fun to play with even when we are not solving linear systems. We can define arbitrary matrices using the matrix command, and specifying the size in row and columns along with the entries of the matrix.

> restart; with(linalg):

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

> A := matrix(3,3, [1,0,-2, 4, 5, -1, 3, -3, 7]);

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

> B := matrix(3,3, [1,0,-2, 4, 5, -1, 3, -3, 7]);

B := matrix([[1, 0, -2], [4, 5, -1], [3, -3, 7]])

You can add two matrials in either of these two ways.

> A + B; evalm(%);

A+B

matrix([[2, 0, -4], [8, 10, -2], [6, -6, 14]])

> matadd( A,B);

matrix([[2, 0, -4], [8, 10, -2], [6, -6, 14]])

You can also multiply a scalar times a matrix in two ways.

> 9*A: % = evalm(%);

9*A = matrix([[9, 0, -18], [36, 45, -9], [27, -27, ...

> scalarmul( A, 9);

matrix([[9, 0, -18], [36, 45, -9], [27, -27, 63]])

You can also create a linear combination of two matrials.

> 9*A + 7*B: % = evalm(%);

9*A+7*B = matrix([[16, 0, -32], [64, 80, -16], [48,...


You can multiply matrices in a manner similar to multiplying numbers. However, instead of simply using the star, you need to use the combination &* to distinguish matrix multiplication from scalar multiplication of a matrix.

> A &* B: % = evalm(%);

`&*`(A,B) = matrix([[-5, 6, -16], [21, 28, -20], [1...

Of course, you can also take matrix powers.

> A^5: % = evalm(%);

A^5 = matrix([[487, 5898, -6064], [1315, 13598, -14...

You can complete the inverse of a matrix using the inverse command. We used this above to help solve equations.

> inverse(A);

matrix([[16/43, 3/43, 5/43], [-31/86, 13/86, -7/86]...

Not all matrices have inverses however. Only those matrices which have a non-zero determinant. We compute the determinant in this way.

> det(A);

86

We can also illustrate a rule of matrices that the determinant of the inverse of a matrix is the multiplicative inverse of the determinant of the matrix.

> det( inverse(A));

1/86

___________________________________________________________________________________

D. Command Summary

___________________________________________________________________________________

Define a System of equations :
System_Name := { list of equations };

Solve a system of equations
solve( sys, {x,y,z});

Generate a matrix and constant vector for a system of equations
genmatrix( sys, [x,y,z], b);

Solve a matrix system, given a coefficient matrix and constant vector
linsolve(A, b);

Row Operations
addrow( A_b, i, j, a ); add a multiple of one row to another (a*Ri + Rj Rj)
swaprow( %, i, j); swap rows i and j (Ri Rj )
mulrow(%, i, a); multiply row i by a ( (a*Ri Ri )
pivot( %, i, j); perform addrows to zero the rest of a j

Automatic Gaussian Elimination
gausselim(A_b);
Automatic Gauss-Jordan Elimination
gaussjord( A_b);
rref( A_b);

Define a matrix
matrix(3,3, [1,0,-2, 4, 5, -1, 3, -3, 7]);

Force a Matrix computation and evaluation
evalm( A)

Matrix operations
Addition A + B;
matadd( A,B) ;

Scalar multiplication 9*A;
scalarmul( A, 9);

Linear combination 9*A + 7*B;
Matrix multiplication A &* B;
Matrix powers A^5;
The Inverse matrix inverse(A);
The Determinant det(A);

>

Find the Solution to the Syten Using Inverse Matrix

Source: https://www.maplesoft.com/applications/view.aspx?SID=4113&view=html