0% found this document useful (0 votes)
27 views

Gauss Elimination Lab Report

rock

Uploaded by

Mukul Khinchi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Gauss Elimination Lab Report

rock

Uploaded by

Mukul Khinchi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Lab Report

Numerical Methods in Chemical Engineering Lab (CHP 215)

2nd YEAR, 3rd SEMESTER, 2022

Lab No # 01

GAUSS ELIMINATION METHOD

INSTRUCTOR:

Dr. MD OAYES MIDDA

[ ]-P k

[ ]- k K

– 3 [ -4]

Lab carried on: Sept 7, 2022

Report submitted on: Sept 14, 2022

Code Algorithm with Sample Calculation (20) ______

Coding (10) ______

Results (10) ______

Comments (05) ______

Self-Trying (05) ______

TOTAL (50) ______

Malaviya National Institute of Technology Jaipur


Department of Chemical Engineering
:- z , , 3, x 4
Type your text
q
Type your text
. .
.
/ . -
. x
. Type your text
ALGORITHM (Flow Chart) –
CODE –
#include<stdio.h>
#include<math.h>
void gaussEliminationLS(int m, int n, double a[m][n], double x[n-1])
{
int i,j,k;
for(i=0;i<m-1;i++)
{
//Partial Pivoting
for(k=i+1;k<m;k++)
{
//If diagonal element(absolute value) is smaller than any of the
terms below it
if(fabs(a[i][i])<fabs(a[k][i]))
{
//Swap the rows
for(j=0;j<n;j++)
{
double temp;
temp=a[i][j];
a[i][j]=a[k][j];
a[k][j]=temp;
}
}
}

//Begin Gauss Elimination


for(k=i+1;k<m;k++)
{
double term=a[k][i]/ a[i][i];
for(j=0;j<n;j++)
{
a[k][j]=a[k][j]-term*a[i][j];
}
}

}
//Begin Back-substitution
for(i=m-1;i>=0;i--)
{
x[i]=a[i][n-1];
for(j=i+1;j<n-1;j++)
{
x[i]=x[i]-a[i][j]*x[j];
}
x[i]=x[i]/a[i][i];
}
}
/*******
Function that reads the elements of a matrix row-wise
Parameters: rows(m),columns(n),matrix[m][n]
*******/
void readMatrix(int m, int n, double matrix[m][n])
{
int i,j;
for(i=0;i<m;i++){
for(j=0;j<n;j++)
{
scanf("%lf",&matrix[i][j]);
}
}
}
/*******
Function that prints the elements of a matrix row-wise
Parameters: rows(m),columns(n),matrix[m][n]
*******/
void printMatrix(int m, int n, double matrix[m][n])
{
int i,j;
for(i=0;i<m;i++){
for(j=0;j<n;j++)
{
printf("%lf\t",matrix[i][j]);
}
printf("\n");
}
}
/*******
Function that copies the elements of a matrix to another matrix
Parameters: rows(m),columns(n),matrix1[m][n] , matrix2[m][n]
*******/
void copyMatrix(int m, int n, double matrix1[m][n], double matrix2[m][n])
{
int i,j;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
matrix2[i][j]=matrix1[i][j];
}
}
}

int main()
{
int m,n,i,j;
printf("Enter the size of the augmeted matrix:\nNo. of rows (m)\n");
scanf("%d",&m);
printf("No.of columns (n)\n");
scanf("%d",&n);
//Declare a matrix to store the user given matrix
double a[m][n];
//Declare another matrix to store the resultant matrix obtained after
Gauss Elimination
double U[m][n];
//Declare an array to store the solution of equations
double x[m];
printf("\nEnter the elements of matrix:\n");
readMatrix(m,n,a);
copyMatrix(m,n,a,U);
printf("\n");
printMatrix(m,n,U);
//Perform Gauss Elimination
gaussEliminationLS(m,n,U,x);
printf("\nThe Upper Triangular matrix after Gauss Eliminiation is:\n\n");
printMatrix(m,n,U);
printf("\nThe solution of linear equations is:\n\n");
for(i=0;i<n-1;i++){
printf("x[%d]=\t%lf\n",i+1,x[i]);
}
}
:–
Comments –
 A system of linear equations is a group of linear equations with various unknown
factors. Gauss elimination method is used to solve a system of linear equations.
Solving a system involves finding the value for the unknown factors to verify all the
equations that make up the system.
 System of equations can be classified as consistent and inconsistent.
1. If there is a single solution that means one value for each unknown factor,
then we can say that the given system is a consistent independent system.
2. If multiple solutions exist, the system has infinitely many solutions; then we
say that it is a consistent dependent system.
3. If there is no solution for unknown factors, and this will happen if there are
two or more equations that can’t be verified simultaneously, then we say
that it’s an inconsistent system.

Name of the system of equations Number of solutions

Consistent independent system 1

Consistent dependent system Multiple or infinitely many

Inconsistent system 0

 We can also use this method to get the rank of the given matrix and thus find its
singular or non-singular nature
An n X n matrix A is non-singular if |A|! = 0 and rank(A) = n
:-

 The above code is generalised for the solution of consistent independent system of
linear equations
 Gaussian Elimination method fails when during row operation the element at the
diagonal becomes zero. It is corrected by swapping the rows such that the diagonals
are always zero
 Time consumption for performing this method on matrices of higher order is huge
 Gauss elimination method is prone to round-off errors. For large matrices these
errors are very much significant and as a result the final result obtained after back
substitution may be very much different from the expected result. It is removed by
pivoting and pass.

You might also like