Lab Report 08
Lab Report 08
Theory:
The elimination of unknowns is used to solve a pair of simultaneous equations. The procedure
consisted of two steps:
1. The equations are manipulated to eliminate one of the unknowns from the equations. The result
of this elimination step is that we have one equation with one unknown.
2. Consequently, this equation could be solved directly and the result back-substituted into one of
the original equations to solve for the remaining unknown.
This basic approach can be extended to large sets of equations by developing a systematic scheme
or algorithm to eliminate unknowns and to back-substitute.
Gauss elimination:
It is the most basic of these schemes. This section includes the systematic techniques for forward
elimination and back substitution that comprise Gauss elimination. Although these techniques are
ideally suited for implementation on computers, some modify cations will be required to obtain a
reliable algorithm.
In particular, the computer program must avoid division by zero. The following method is called
“naive” Gauss elimination because it does not avoid this problem. Subsequent sections will deal
with the additional features required for an effective computer program.
The approach is designed to solve a general set of n equations:
As was the case with the solution of two equations, the technique for n equations consists of two
phases: elimination of unknowns and solution through back substitution.
Lab 08 Gauss Elimination in MATLAB
where the prime indicates that the elements have been changed from their original values. The
procedure is then repeated for the remaining equations.
Back Substitution:
....................6
This result can be back-substituted into the (n 2 l)th equation to solve for xn21. The procedure,
which is repeated to evaluate the remaining x’s, can be represented by the following formula:
The two phases of Gauss elimination: forward elimination and back substitution. The primes
indicate the number of times that the coefficients and constants have been modified.
Now, perform the following elementary row operations till it is reduced to echelon form by:
Lab 08 Gauss Elimination in MATLAB
Thus, the solution of above system of linear equation is (a, b, c) i.e. x = a, y = b and z = c.
MATLAB Code:
>>C = [1 2 -1; 2 1 -2; -3 1 1]
>>b= [3 3 -6]'
>>A = [C b]; %Augmented Matrix
>>n= size(A,1); %number of eqns/variables
>>x = zeros(n,1); %variable matrix [x1 x2 ... xn] coulmn
>>for i=1:n-1
>> for j=i+1:n
>> m = A(j,i)/A(i,i)
>> A(j,:) = A(j,:) - m*A(i,:)
>> end
>>end
>>x(n) = A(n,n+1)/A(n,n)
>>for i=n-1:-1:1
>> summ = 0
>>for j=i+1:n
>>summ = summ + A(i,j)*x(j,:)
>>x(i,:) = (A(i,n+1) - summ)/A(i,i)
>>end
>>end
Lab 08 Gauss Elimination in MATLAB
Input:
Output: