Gauss Elimination Lab Report
Gauss Elimination Lab Report
Lab No # 01
INSTRUCTOR:
[ ]-P k
[ ]- k K
– 3 [ -4]
}
//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.
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.