# 213 - A3 - Row Reduction

## 527 days ago by Professor213

Row Reduction using Gauss-Jordan Elimination - In this worksheet, the user enters the coefficients for a $MxN$ linear system.  The intermediate steps for perfoming Gauss-Jordan Elimination are output.  The user can choose a random matrix of given dimension or enter a specific matrix.  The user can also choose to perform only regular echelon form where only the entries below the main diagonal are zeroed out.

John Travis

Mississippi College

Assignment...using the cells below, create a 4x5 problem where the worksheet creates the matrix randomly.  Then, write out the elimination commands needed for each of step along the way in reducing the original matrix to reduced row echelon form--RREF.  Put your answers at the bottom of this worksheet with the commands for each stage in a different text box.

For example, you might write:

Step 1:

$-3*R_1+R_3\rightarrow R_3$ , or without using latex and just using text, -3 R1 + R3 -> R3

blah, blah, blah

Step 2:

blah, blah, blah

%hide %auto M=3 N=3 print html("<font size=+2 color=blue>For your system, first select the number of rows and columns.</font> <br><p>") @interact def _(Rows=[3,4,5,6],Cols=[3,4,5,6,7],auto_update=True): global M,N M = Rows N = Cols return M,N

<font size=+2 color=blue>For your system, first select the number of rows and columns.</font> <br><p>
Rows
Cols
auto_update

## Click to the left again to hide and once more to show the dynamic interactive window

print M,N
 4 5 4 5
%auto # You may need to evaluate this cell to implement the remainder of this assignment # This cell takes an input (or randomly created rational) matrix and outputs the Gauss-Jordan result # following each step in the process. pretty_print(html("<font size=+2 color=blue>Enter your data below. You can tab to navigate between cells. Click Update when you are finished. If you want a random matrix, click the box and then update.</font><p>")) # global Astart Astart = zero_matrix(QQ,M,N) @interact def _(Input_Matrix=Astart,reduced_echelon_form=True, auto_update=False,Make_it_random=False): if Make_it_random: A = random_matrix(QQ,M,N,num_bound=20, den_bound=4) else: A = Input_Matrix # if A.det()==0: # print html("<font size=+1 color=red>Matrix is Singular. Please pick another!</font>") pretty_print(html("<font size=+2 color=blue>Using the matrix</font>")) show(A) global Astart Astart = copy(A) # Now, let's start the step by step Gauss-Jordan routine ROWS = range(M) COLS = range(N) PIVOTS = range(min(M,N)) for i in PIVOTS: # Gauss-Jordan on column i # First, make the pivot element equal to 1 k = i # Need to fix this when a column is skipped when finding nonzero pivots # That is, if the remainder of a column is zero, go on to the next column till you reach the end. if A[i][i]==0: # swap for non-zero pivot # start looking in rows below the i-th while (k<M and A[k][i]==0): k += 1 if k==M: print 'All of the remaining rows are zero. Move to next columns or finish.' else: A.swap_rows(i,k) # So, now we should have a non-zero in the pivot position or k=M which means we are done. # Should consider using the function "nonzero_positions_in_column(i)" and use the min position > i. # Start zeroing out the rest of column i. if A[i][i]<>0: A[i]=A[i]/A[i][i] if reduced_echelon_form: for k in ROWS: if i<>k: A[k] = A[k]-A[i]*A[k][i] else: for k in ROWS: if i<k: A[k] = A[k]-A[i]*A[k][i] print '\n After',i+1,'step(s) the matrix is equivalent to:' show(A)

Enter your data below. You can tab to navigate between cells. Click Update when you are finished. If you want a random matrix, click the box and then update.

Input_Matrix
reduced_echelon_form
Make_it_random

## Click to the left again to hide and once more to show the dynamic interactive window

1show(Astart)
 Traceback (click to the left of this block for traceback) ... SyntaxError: invalid syntax Traceback (most recent call last): File "", line 1, in File "_sage_input_18.py", line 10, in exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("MXNob3coQXN0YXJ0KQ=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py")) File "", line 1, in File "/tmp/tmpK__5Nc/___code___.py", line 2 1show(Astart) ^ SyntaxError: invalid syntax
# The matrix you eventually used above was Astart
 [ -4 -1 -6 16 -5 4 0 2] [ 9/2 -6 1 6 9/4 2 5/2 -13/2] [ 10 -3/2 19/3 18 -15/4 12 -3/2 7/3] [ -4 -1 -6 16 -5 4 0 2] [ 9/2 -6 1 6 9/4 2 5/2 -13/2] [ 10 -3/2 19/3 18 -15/4 12 -3/2 7/3]
# For saving your matrix for later use, cut and paste the result from above into the correct spot below. # To use this again, you will need to add the correct number of commas in the right places. My_A = matrix([ [ 1, -34/9, -1, 1/2, 2, -2], [ -1, -2, 3, -1, 1, 1/2], [ -3/4, 1/2, 1/3, -1/2, 1/6, 3/2], [ 3, 1/4, -1/14, 7/361, -4/3, -4] ])

STEP 1:

Double click on this text to enter step 1:

STEP 2:

Double click on this text to enter step 2:

STEP 3:

Double click on this text to enter step 3:

STEP 4:

Double click on this text to enter step 4: