SmtC: Show me the Code
Ole Peter Smith
Instituto de Matemática e Estatística
Universidade Federal de Goiás
http://www.olesmith.com.br

Eliminação do Gauss
Viver é algo que se faz agora ou nunca...
Qual você faz?
Piet Hein
< Matrices | Gauss Forward | Pivotação Parcial >

Gauss Forward

  • Gauss Forward:
    Python Listing: ../../../Code/Gauss.py.
    def Gauss_Forward_1(A,b=[]):
        det=1.0
        for i in range( len(A) ):
            if (A[i][i]==0.0):
                print "Gauss_Forward_1: Matrix Singular at ",i,"x",i
                return 0.0
                
            det*=A[i][i]
            fact=1.0/A[i][i]
            Matrices_Row_Mult(A,i,fact)
            if (b): b[i]*=fact
    
            for j in range( i+1,len(A) ):
                if (b): b[j]-=A[j][i]*b[i]
                Matrices_Rows_Operation(A,j,-A[j][i],i)
    
        return det
    
    
    
    
    
    
    Python Listing: test.py.
    from Vector import *
    from Matrix import *
    from Gauss import *
    
    A=[
        [1,2,4],
        [1,3,9],
        [1,4,16],
    ]
    Matrix_Print(A)
    
    v=[2,3,4]
    
    det=Gauss_Forward_1(A,v)
    
    Matrix_Print(A)
    Vector_Print(v)
    
    print "Det(A)=",det
    
    [
        [1.000000,2.000000,4.000000]
        [1.000000,3.000000,9.000000]
        [1.000000,4.000000,16.000000]
    ]
    [
        [1.000000,2.000000,4.000000]
        [0.000000,1.000000,5.000000]
        [0.000000,0.000000,1.000000]
    ]
    [2.000000,1.000000,0.000000]
    Det(A)= 2.0
    
    
    Output from: /usr/bin/python test.py
< Matrices | Gauss Forward | Pivotação Parcial >
Messages:
0 secs.