Welcome guest
You're not logged in.
348 users online, thereof 0 logged in

## Example: The Gaussian Method in Practice

The following example will demonstrate the Gaussian method by example.

### Example

We want to solve the system of linear equations with three unknowns

$$\begin{array}{rcr} x_1 -3x_2 +2x_3&=&1\\ 5x_1 + 4x_2 -3x_3&=&4\\ 2x_1 -8x_2 +4x_3&=& -2\\ \end{array}\quad\quad( * )$$

This system has the following extended coefficient matrix:

$$A|\beta:= \left(\begin{array}{rrr|r} 1&-3&2&1\\ 5&4&-3&4\\ 2&-8&4&-2\\ \end{array}\right)$$

In the following, we use SageMath. You will have to click the evaluate buttons to see the results.

print "Original extended matrix:" A=matrix(QQ,[[1,-3,2,1],[5,4,-3,4],[2,-8,4,-2]]) print(A); print; print "STEP 1: Bring the matrix to the upper-triangular form"; print "Adding the -5-fold multiple of the first row to the second:" A1=A A1[1]=A1[1]-5*A1[0] print(A1);print "Adding the -2-fold multiple of the first row to the third:" A1[2]=A1[2]-2*A1[0] print(A1);print "Adding the 2/19-fold multiple of the second row to the third:" A1[2]=A1[2]+2/19*A1[1] print(A1)

The resulting upper-triangular matrix is

$$A|\beta:= \left(\begin{array}{rrr|r} 1&-3&2&1\\ 0&19&-13&-1\\ 0&0&-\frac{26}{19}&-\frac{78}{19}\\ \end{array}\right)$$

Now we can use the backward substitution to solve the system

print "STEP 2: Backward substitution:" A=matrix(QQ,[[1,-3,2,1],[0,19,-13,-1],[0,0,-26/19,-78/19]]) print(A); print; print "Setting x3=-78/19*(-19/26), substituting x3 in second row, setting x2=...etc...." x3=A[2][3]/A[2][2] x2=(A[1][3]-A[1][2]*x3)/A[1][1] x1=(A[0][3]-A[0][2]*x3-A[0][1]*x2)/A[0][0] print "x3=", x3 print "x2=", x2 print "x1=", x1

Therefore, $x_1=1, x_2=2, x_3=3$ is the solution of the system $( * ).$

| | | | created: 2018-04-15 18:13:46 | modified: 2018-04-15 20:37:16 | by: bookofproofs | references: [7937]