This method is defined as a set finite of operations whereby is direct. The principal idea of the method is convert a system of equations in other equivalent simpler, by elemental operations of line.
How the method works:
Given a system of equations AX=b, where A represent the matrix of coefficients of size nxn, X the vector column of unknown quantity and b the vector of term independent terms; will proceed in the following way:
1. To get the matrix increase Ab of the system.
2. To convert all elements under of A11 in zeros using the second operation introduce before. In the process to find a multiplier.
3. To convert in zeros all elements under A22.
4. To continue with a similar process to the 3 and 4 processes until to get a triangular matrix, that is, a matrix with all elements under the principal diagonal equal to 0.
5. To find the value of the Xn term, with this value to find Xn-1 and like this with regressive substitution until get the X1 term.
Problems that the method can present:
An element of diagonal is 0: If in someone stage of the process an element of the principal diagonal is 0 then to have a division by zero in the moment of to calculate the multiplier, considering that, this is defined how Aik/Akk.
An element of the diagonal is near to zero: In this case, as in the previous problem, the element will be in the denominator of the division that define the multiplier. In consequence, will be violating one of the rules to avoid to effect of rounding errors.
Propagation and rounding error: Is the error that to expand in the intermediate operations maked and that to have influence in the result.
Pseudo-code
In the next pseudo-code, A is the matrix of coefficients nxn, b is the vector of independent terms and K is the counter of the stages.
Function eliminación gaussiana (A,b,n)
Ab=Matriz aumentada [Ab]
for k=1 to n-1 do
for i=k+1 to n do
multiplicador=Abik/Abkk
for j=k to n+1 do
Abij=Abij-multiplicador*Abkj
end for
end for
end for
Xn1=(Abnn+1)/(Abnn)
for i=n-1 to 1 step -1
sumatoria=0
for p=i+1 to n
sumatoria=sumatoria +Abip*Xp1
end for
Xi1=(Abin+1-sumatoria)/Abii
end for
end function
Code
function [x]=eliminacion_gaussiana(A,b,n)
Ab=[A,b];
for k=1:n-1
for i=k+1:n
multiplicador=(Ab(i,k))/(Ab(k,k));
for j=k:n+1
Ab(i,j)=Ab(i,j)-multiplicador*Ab(k,j);
end
end
end
x(n,1)=(Ab(n,n+1))/(Ab(n,n));
for i=n-1:-1:1
sumatoria=0;
for p=i+1:n
sumatoria=sumatoria + Ab(i,p)*x(p,1);
end
x(i,1)=(Ab(i,n+1)-sumatoria)/Ab(i,i);
end
end