Vous êtes sur la page 1sur 3

International Islamic University Chittagong

Department of EEE
Course No. EEE-2410
Experiment No. 6
Name of the Experiment: Determination of Direct Solution of Linear Equations using
Gauss Elimination Method.
A sample set of Linear Equations is shown below,
2x + 3y - 5z = 4
x + y - 2z = 3
3x y + z = -5

Gauss Elimination Method is used to solve these type of Linear equation set.

we will make a matrix like below,


2
1
3

3 -5
1 -2
-1 1

4
3
-5

now we will follow these steps,


1. take the row with highest absolute value of the first element. Here, it is the third
one.
2. inter change the row with the first row. Now the matrix looks like,
3
1
2

-1 1
1 -2
3 -5

-5
3
4

3. make the first element of the first row 1 by dividing the entire row by itself
1.0000 -0.3333 0.3333 -1.6667
1
1
-2
3
2
3
-5
4
4. make the first element zero(0) of other rows using first row. Here, if we make new
r2 = r2 - r1, and r3 = r3 - r1*2; then the matrix becomes;
1.0000 -0.3333 0.3333 -1.6667
0 1.3333 -2.3333 4.6667
0 3.6667 -5.6667 7.3333
5. now if we take a smaller matrix from 2nd row and 2nd column and repeat from step
1, we get,

1.0000 -0.3333 0.3333 -1.6667


0 1.0000 -1.5455 2.0000
0
0
-0.2727 2.0000
6. if we complete all rows in this way, we get,
1.0000 -0.3333 0.3333 -1.6667
0 1.0000 -1.5455 2.0000
0
0
1.0000 -7.3333
7. here, z = -7.3333; now if we solve these two easy equations, we can get y and x
respectively,
y 1.5455*z = 2
and
x - 0.3333*y +0.3333*z = -1.6667
code for Gauss Elimination in MATLAB
clc;
clear all;
x=[2 3 -5 4;1 1 -2 3;3 -1 1 -5];
n= length(x)-1;
for i=1:n
max=0;
max_row=0;
for j= i:n
if(abs(x(j,i))>max)
max_row=j;
end
end
temp = x(i,1:(n+1));
x(i,1:(n+1))= x(max_row,1:(n+1));
x(max_row,1:(n+1))=temp;
piv_point=x(i,i);
for j=i:(n+1)
x(i,j)=x(i,j)/piv_point;
end

for j=(i+1):n
fctr=x(j,i);
for k=i:(n+1)
x(j,k)=x(j,k)-x(i,k)*fctr;
end
end
end

Vous aimerez peut-être aussi