Ask Your Question

jh's profile - activity

2016-04-02 13:43:54 -0600 received badge  Nice Question (source)
2015-08-06 08:50:20 -0600 received badge  Famous Question (source)
2013-11-17 11:10:59 -0600 received badge  Good Answer (source)
2013-10-15 11:47:16 -0600 received badge  Notable Question (source)
2013-01-27 10:54:36 -0600 received badge  Popular Question (source)
2012-04-06 09:27:04 -0600 commented answer How to show the steps of Gauss' method

That *is* a nice interact. BTW, in case you can use it and need an explicit statement, license is pd.

2012-04-05 17:41:44 -0600 received badge  Nice Answer (source)
2012-04-05 15:28:37 -0600 received badge  Teacher (source)
2012-04-05 15:28:37 -0600 received badge  Self-Learner (source)
2012-04-05 11:52:08 -0600 answered a question How to show the steps of Gauss' method

In case it saves anyone some time, I am using the following routine. Since this is for pedagogical purposes only, I restricted the matrices to rational entries. Bug reports welcome.

# Naive Gaussian reduction
def gauss_method(M,rescale_leading_entry=False):
    """Describe the reduction to echelon form of the given matrix of rationals.

    M  matrix of rationals   e.g., M = matrix(QQ, [[..], [..], ..])
    rescale_leading_entry=False  boolean  make the leading entries to 1's

    Returns: None.  Side effect: M is reduced.  Note: this is echelon form, 
    not reduced echelon form; this routine does not end the same way as does 
    M.echelon_form().

    """
    num_rows=M.nrows()
    num_cols=M.ncols()
    print M    

    col = 0   # all cols before this are already done
    for row in range(0,num_rows): 
        # ?Need to swap in a nonzero entry from below
        while (col < num_cols
               and M[row][col] == 0): 
            for i in M.nonzero_positions_in_column(col):
                if i > row:
                    print " swap row",row+1,"with row",i+1
                    M.swap_rows(row,i)
                    print M
                    break     
            else:
                col += 1

        if col >= num_cols:
            break

        # Now guaranteed M[row][col] != 0
        if (rescale_leading_entry
           and M[row][col] != 1):
            print " take",1/M[row][col],"times row",row+1
            M.rescale_row(row,1/M[row][col])
            print M
        change_flag=False
        for changed_row in range(row+1,num_rows):
            if M[changed_row][col] != 0:
                change_flag=True
                factor=-1*M[changed_row][col]/M[row][col]
                print " take",factor,"times row",row+1,"plus row",changed_row+1 
                M.add_multiple_of_row(changed_row,row,factor)
        if change_flag:
            print M
        col +=1
2012-04-01 06:10:49 -0600 commented question How to show the steps of Gauss' method

Thanks for the reply. It is for pedagogical purposes. I'll think about implementing it.

2012-03-31 10:04:18 -0600 received badge  Student (source)
2012-03-31 07:09:50 -0600 asked a question How to show the steps of Gauss' method

I am new to Sage, so I apologize if this is dopey. I can get a matrix in Sage and I can get its reduced echelon form. I can get Sage to show the result of a single Gauss' method row operation. But is there a way to get Sage do Gauss' method out to reduced echelon form, while showing the steps? It would be especially sweet if it showed the intermediate matrices.