Finding Funamental Set of Solutions for 3x3 Matrix
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); ___________________________________________________________________________________ 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, > solve( sys, {x,y,z}); 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(%); AUTOMATIC MATRIX SOLUTION We can also convert this system of equations to a matrix systems. > A := genmatrix( sys, [x,y,z], b); > evalm(b); 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); This is useful if you start with a matrix equation to begin with, and so Maple INVERSE MATRIX SOLUTION > inverse(A); > evalm( inverse(A) &* b); The evalm command forces a matrix computation and expresses the result. DEPENDENT SYSTEMS > sys := { x + y -2*z = -4, x - 2*y + z = 3, 2*x -y -z = -1}; > solve( sys, {x,y,z}); > A := genmatrix( sys, {x,y,z}, b); > evalm(b); > linsolve(A, b); 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 > det(A); > sys := { x + y + z = 8, x + y - 3*z = 10, > solve( sys, {x,y,z}); > A := genmatrix( sys, {x,y,z}, b); > linsolve(A, b); > evalm( inverse(A) &* b); Nothing seems to work, because nothing can work. There is no solution, and so Maple offers to do nothing! ___________________________________________________________________________________ B. Gauss-Jordan Elimination ___________________________________________________________________________________ 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 , > A := genmatrix( sys, [x,y,z], b); > evalm(b); 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); ROW OPERATIONS The three row operations are > evalm(A_b); 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); Next we swap rows 1 and 3 to get the 1 in the (1,1) position. > swaprow( %, 1, 3); 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); > addrow( %, 2, 3, 2); 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); > addrow( %, 2, 1, 13); > addrow( %, 2, 3, 13); Finally, we multiply row 3 by -45/28, and add multiples to complete the problem. > mulrow( %, 3, -45/28); > addrow( %, 3, 2, -29/45); > addrow( %, 3, 1, 28/45); 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); > mulrow( %, 1, 1/6); > pivot( %, 1, 1); Now get a 1 in the (2,2) position, and prvot on that position. > mulrow( %, 2, -2/13); > pivot( %, 2, 2); And finally pivot the (3,3) poition. > pivot( %, 3, 3); AUTOMATIC REDUCTION > gausselim( A_b); 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); > rref( A_b); 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): > A := matrix(3,3, [1,0,-2, 4, 5, -1, 3, -3, 7]); > B := matrix(3,3, [1,0,-2, 4, 5, -1, 3, -3, 7]); You can add two matrials in either of these two ways. > A + B; evalm(%); > matadd( A,B); You can also multiply a scalar times a matrix in two ways. > 9*A: % = evalm(%); > scalarmul( A, 9); You can also create a linear combination of two matrials. > 9*A + 7*B: % = evalm(%); > A &* B: % = evalm(%); Of course, you can also take matrix powers. > A^5: % = evalm(%); You can complete the inverse of a matrix using the inverse command. We used this above to help solve equations. > inverse(A); Not all matrices have inverses however. Only those matrices which have a non-zero determinant. We compute the determinant in this way. > det(A); 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)); ___________________________________________________________________________________ D. Command Summary ___________________________________________________________________________________ Define a System of equations : Solve a system of equations Generate a matrix and constant vector for a system of equations Solve a matrix system, given a coefficient matrix and constant vector Row Operations Automatic Gaussian Elimination Define a matrix Force a Matrix computation and evaluation Matrix operations Scalar multiplication 9*A; Linear combination 9*A + 7*B; >
Warning, the protected names norm and trace have been redefined and unprotected
4*x - y + 5*z = -3};
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.
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.
An inconsistent system has not solution. Maple generally, refuses to answer questions which have no answer.
x + y - z = 1 };
Error, (in inverse) singular matrix
In such case, det = 0.......
One of the most important methods used to solve a matrix system is Gauss-Jordan Elimination using row operations. The idea is this:-
4*x - 7*y - 7*z = 9 ] ;
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.
Now, instead of adding various multiples of row 1 to the other rows, simply pivot on that (1,1) position.
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.
Warning, the protected names norm and trace have been redefined and unprotected
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.
System_Name := { list of equations };
solve( sys, {x,y,z});
genmatrix( sys, [x,y,z], b);
linsolve(A, b);
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
gausselim(A_b);
Automatic Gauss-Jordan Elimination
gaussjord( A_b);
rref( A_b);
matrix(3,3, [1,0,-2, 4, 5, -1, 3, -3, 7]);
evalm( A)
Addition A + B;
matadd( A,B) ;
scalarmul( A, 9);
Matrix multiplication A &* B;
Matrix powers A^5;
The Inverse matrix inverse(A);
The Determinant det(A);
Finding Funamental Set of Solutions for 3x3 Matrix
Source: https://www.maplesoft.com/applications/view.aspx?SID=4113&view=html