213 - A3 - Row Reduction

699 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 
       
For your system, first select the number of rows and columns.

Rows 
Cols 
auto_update 

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

print M,N 
       
3 4
3 4
%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. 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>") 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

show(Astart) 
       

                                
                            

                                
# The matrix you eventually used above was Astart 
       
[ -8/3   3/2    11 -19/3    -5    13     6]
[   -3     0     6    -3   -14    -5    17]
[    1    19   -10     5    10    12   9/4]
[   15     2    -3     7     0   -20    11]
[   -6  13/3    10    10     0     5   5/2]
[ -8/3   3/2    11 -19/3    -5    13     6]
[   -3     0     6    -3   -14    -5    17]
[    1    19   -10     5    10    12   9/4]
[   15     2    -3     7     0   -20    11]
[   -6  13/3    10    10     0     5   5/2]
# 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: