Documente Academic
Documente Profesional
Documente Cultură
Two phases:
o forward elimination
For k = 1 to n-1
For i = k+1 to n
factor = Aik / Akk
For j = k+1 to n
Aij = Aij - factor * Akj
Bi = BI - factor * Bk
o back substitution
Potential errors
o Division by zero - The method of Gauss Elimination outlined above is
sometimes called Naive Gauss Elimination because it is possible to
divide by zero during the forward elimination or the back substitution
phases when blindly following the algorithm. The process called partial
pivoting is used to swap two rows of coefficients when necessary in
order to place the maximum coefficient of a given term in the proper row
and avoid division by zero. (Complete pivoting involves swapping
columns but is rarely used due to extra, difficult-to-program side
requirements.)
The following pseudocode for partial pivoting could be used:
p=k
big = abs(Akk)
For ii = k+1 to n
dummy = abs(Aii,k)
If dummy > big
big = dummy
p = ii
If p != k
For jj = k to n
dummy = Ap,jj
AP,jj = Ak,jj
AK,jj = dummy
dummy = Bp
BP = Bk
Bk = dummy
o Round-off errors - As always, a computer must round off values in
order to compute and store values. In systems, with large numbers of
equations, these round-off errors can snowball (propagate) into larger
errors as the algorithm proceeds. Also, if some coefficients are extremely
large and others are very small, round-off errors tend to affect answers.
So scaling the equations so that the maximum coefficient for each term
is the value one will decrease round-off error. Sometimes, scaling is just
used to determine if equations should be pivoted. Always, backsubstitute results into the original equations of the system in order to
check your answers to decide if round-off error is significant.
o Ill-conditioned systems - If a small change in one or more coefficients'
values leads to a great change to the solution of the system, the system is
said to be ill-conditioned. Otherwise, the system is considered to be wellconditioned. In fact, round-off errors can cause large errors in the
computed solutions in ill-conditioned systems. It is sometimes possible
to scale the equations so that the maximum element in any row is 1.
Using the most precise data type is advisable to avoid having an illconditioned system spoil your attempt at finding a solution.
o Singular systems - If a system is singular, then it's determinant is zero.
Furthermore, the determinant of a triangular system can easily be
computed by multiplying the diagonal entries. Therefore, it is worthwhile
to check the determinant of a system with this simple computation after
forward elimination.
Pseudocode for Gauss Elimination - Notice that the scaling is not used to
manipulate the equations only to check if pivoting should be performed. Also,
notice that the determinant is checked by computing the diagonal terms to find
singular systems. The term er is used to indicate whether or not a singular
system has been found. The term tol is set by the user to determine the user's
tolerance for near-zero occurrences.
Sub Gauss(A,B,n,X,tol,ER)
Dim S(n)
ER= 0
For i = 1 to n
Si = abs(Aij)
For j = 2 to n
If abs(Aij) > Si Then Si = abs(Aij)
Call Eliminate(A, S, n, B, tol, ER)