Gaussian EliminationWritten by Michael K. May, S.J., revised by Russell Blythrestart: with(LinearAlgebra): with(plots): with(plottools):OutlineThe basic objectives are:1) Converting between systems of equations and matrices2) Using Maple commands for elementary row operations3) Using more general Maple commands on matrices.Part 1: Converting between systems and matricesThe text points out that the Gaussian elimination method we used on systems of equations can be performed in shorthand by working on the matrix of coefficients of the system. In Maple the command for converting from a system of equations to a matrix is GenerateMatrix. To convert back from a matrix to a system of equations, the command is GenerateEquations. Each of these commands has two forms, one for the matrix of coefficients, and one for the augmented matrix. These commands are part of the LinearAlgebra package.To convert from a system of equations to a matrix we first need a list of equations, and an ordered list of variables.eq1 := x + y + 2*z + w = 1;
eq2 := 3*x - 4*y + z + w = 2;
eq3 := 4*x - 3*y + 3*z + 2*w = 3;
eqlist := [eq1, eq2, eq3];
varlist := [x, y, z, w];If we want the matrix of coefficients, the command GenerateMatrix has three parameters: the list of equations, the list of variables, and the name `augmented`. It produces the augmented matrix. If we forget the augmented option, the command returns an ordered pair composed by the coefficient matrix and the vector of constants. M1 := GenerateMatrix(eqlist, varlist, `augmented`);
(M2,b) := GenerateMatrix(eqlist, varlist);
M2 := GenerateMatrix(eqlist, varlist)[1];
To convert back from a matrix to a system of equations we use the GenerateEquations command. To produce a system with the constants set to zero (that is, a homogeneous system) we use two parameters: the matrix of coefficients and the variable list. For a nonhomogeneous system, we either use a third parameter, a vector of constants, or we use the augmented matrix.homsys := GenerateEquations(M2,varlist);
nonhomsys := GenerateEquations(M2,varlist,b);
nonhomsys2 := GenerateEquations(M1,varlist);Exercises1) Use Maple to convert the system{x-y+2z-2w=1, 2x+y+3w=4, 2x+3y+2z=6} to an augmented matrix.2) Use Maple to convert the augmented matrix NiMtSSdtYXRyaXhHNiI2IzcmNyciIiFGKSIiIyIiJSIiIjcnIiIkRixGKiIiJ0YpNydGLEYsRixGLEYsNydGKUYsRiosJEYsISIiRiw= to a system of equations in x, y, z, and w.3) Use the command N1 := RandomMatrix(3, 5); to generate a random 3 by 5 matrix named N1. Convert it to a system of equations in x, y, z, and w.Part 2: Elementary row operationsOnce we have a system of equations converted to an augmented matrix, the next task is to use elementary row operations to perform Gaussian elimination on the matrix. The linalg package of Maple has a command corresponding to each type of elementary row operation. The command RowOperation(M, [r1, r2], scal);is used to add scal times row r2 of matrix M to row r1. The commandRowOperation(M, r1, scal);is used to multiply row r1 of M by scal. The command RowOperation(M, [r1, r2]);is used to switch rows r1 and r2 of the matrix M.We use these operations to reduce the matrix M2 above to row echelon form.print(M1);M3a := RowOperation(M1,[2,1],-3);M3b := RowOperation(M3a,[3,1],-4);M3c := RowOperation(M3b,[3,2],-1);This completes Gaussian elimination on the system. If instead we want to perform Gauss-Jordan elimination, we continue on to the reduced row echelon form.M3d := RowOperation(M3c,2,-1/7);M3e := RowOperation(M3d,[1,2],-1);Exercises:4) Use elementary row operations on the matrix N1 from exercise 3 to obtain a row equivalent matrix in echelon form.5) Use more row operations to reduce N1 to a row equivalent matrix in reduced echelon form.Part 3: Some more powerful linear algebra commandsGaussian elimination and Gauss Jordan elimination are standard techniques in linear algebra. Rather than use row operations one by one, they can be performed with the GaussianElimination and ReducedRowEchelonForm commands.GaussianElimination(M1);
ReducedRowEchelonForm(M1);Sometimes we do not need the reduced matrix, but only the number of nonzero rows in the reduced matrix. This is found using the Rank command. The transpose of a matrix is given by the Transpose command.Rank(M1);
Transpose(M1);We started this section by converting systems of equations into matrix form. The command LinearSolve(MatrixCoefficients, ConstantVector); finds the solution to a system which has MatrixCoefficients as the matrix of coefficients, and ConstantVector the vector of constants.gensol := LinearSolve(M2, b);The _t0i are Maple-provided parameters in the solution vectors. We can find a translation vector by setting the parameters to zero.transvec := eval(gensol,{_t0[1]=0, _t0[2]=0});Spanning vectors are obtained by setting each parameter to 1 in turn and subtracting off the translation vectors.svec1 := eval(gensol,{_t0[1]=1, _t0[2]=0});
spanvec1 := svec1- transvec;
svec2 := eval(gensol,{_t0[1]=0, _t0[2]=1});
spanvec2 := svec2 - transvec;Exercise:6) Find the general solution to the system of equations you generated in Exercise 3 above.