Lab 5 Gauss Elimination
Lab 5 Gauss Elimination
Lab No: 5
Section: A
Software:
MATLAB
Theory:
Basically, we do computations and visualization in MATLAB. In this lab, we did the
computations. We learn how to write the matrices in MATLAB and perform the arithmetic
operations on matrices. We learn how to find roots of system of linear of equations by using
the gauss elimination and then use the back substitution method in MATLAB. Linear equations
have more than one variable. It gives a straight line when plotted in graph. Back substitution
means to transform the matrix in row echelon or reduced row echelon form. First, solve the last
equation and the move towards first. In gauss elimination method, we transform the matrix into
reduced echelon form.
12x-2y+3z=18
x+10y-2z=16
3x+y+15z=52
MATLAB Code:
%12x-2y+3z=18
%x+10y-2z=16
%3x+y+15z=52
A=[12 -2 3;1 10 -2;3 1 15]; %write matrix A
b=[18;16;52]; % write matrix b
[n,~]=size(A);
x=zeros(n,1);
%coding for forward elimination.
for i=1:n-1
m=A(i+1:n,i)/A(i,i);
A(i+1:n,:)=A(i+1:n,:)-m*A(i,:);
b(i+1:n,:)=b(i+1:n,:)-m*b(i,:);
end
%now coding for back substitution method.
x(n,:)=b(n,:)/A(n,n);
for i=n-1:-1:1
x(i,:)=(b(i,:)-A(i,i+1:n)*x(i+1:n,:))/A(i,i);
end
x
Results:
Conclusion:
After performing this lab, we come to know about the computations in MATLAB and basic
operations that we did on matrices in MATLAB. We write the code for Gauss elimination
method to determine the roots of system of linear equations. We successfully determine the
roots of equations by transforming the matrix into reduce echelon form and then use the back
substitution.