To solve the linear equation using Gauss Elimination Method

Program to solve the linear equation using Gauss Elimination Method, the complete algorithm for Gauss Elimination Method is given below.
The Gauss Elimination process involves two techniques for solving linear equation. The first one is forming upper triangular matrix by forward elimination and the second is using backward substitution method to find the unknown values.


//lab 6 to solve the linear equation using Gauss Elimination method.
/* complete algorithm for Gauss Elimination Method
1. read n number of equation
2. for i=1 to n
3. for j=1 to n+1
4. read aij
5. end for j
6. end for i.
7. for k=1 to n-1
for i=k+1 to n
9. pivot=aik/akk
10. for j=1 to n+1
11. aij=aij-(pivot*akj)
12. end for j
13. end for i
14. end for k
15. xn=a(n n+1)/a(n n)
16. for k=n-1 to 1
17. sum=0.0
18. for j=k+1 to n
19. sum =sum+(akj*xj)
20. end for j
21. xk=(a(k n+1) -sum)/akk
22. end for k
23. for i=1 to n
24. print xi
25. end for i
26. stop
*/
#include
#include
#include
#include
void main()
{
double n,i,j, k;
double sum, pivot, a[10][10], x[10];
clrscr();
cout<<“Enter No of equations, n :\t”;
cin>>n;
cout<<<“\tDONOT ENTER DIAGONAL ELEMENT ZERO\n”;
/* Start Reading Equations */
for(i=1;i<=n;i++)
{
cout<<<“Supply coefficients of “<<<” equation”<
for(j=1;j<=n+1;j++)
{
cout<<“a”<<<<“=\t”;
cin>>a[i][j];
}
}
/* Start of Elimination */
for(k=1;k<=n-1;k++)
{
for(i=k+1;i<=n;i++)
{
pivot=a[i][k]/a[k][k];
for(j=1;j<=n+1;j++)
a[i][j]=(a[i][j]-(pivot*a[k][j]));
}
}
/* Start Back Substitution */
x[n]=(a[n][n+1]/a[n][n]);
for(k=n-1;k>=1;k–)
{
sum=0.0;
for(j=k+1;j<=n;j++)
{
sum=sum+(a[k][j]*x[j]);
}
x[k]=(a[k][n+1]-sum)/a[k][k];
}
/* Displaying Result */
cout<<<“Required roots are:”<
for(i=1;i<=n;i++)
cout<<” x”<<<“= “<<
getch();
}


To solve the linear equation using Gauss Elimination Method in C++ Programming Language for Numerical Methods for Engineering Students

About The Author

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top