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

Computer Oriented Numerical Methods 4

This document describes a lab experiment on solving a set of linear equations using the Gauss-Seidel method. The algorithm initializes the variables, reads the matrix coefficients and right-hand side values, then iteratively solves for each unknown using the most recent approximations until the results converge within a set tolerance. The C code implements this algorithm, taking the matrix and loading values, performing the iterative calculations, and outputting the final solution values. Comments note that diagonal dominance testing and partial pivoting were included before iteration to improve convergence.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views

Computer Oriented Numerical Methods 4

This document describes a lab experiment on solving a set of linear equations using the Gauss-Seidel method. The algorithm initializes the variables, reads the matrix coefficients and right-hand side values, then iteratively solves for each unknown using the most recent approximations until the results converge within a set tolerance. The C code implements this algorithm, taking the matrix and loading values, performing the iterative calculations, and outputting the final solution values. Comments note that diagonal dominance testing and partial pivoting were included before iteration to improve convergence.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

LAB 4:

TITLE: SOLUTION OF SET OF LINEAR EQUATION USING GAUSS SIEDEL METHOD


ALGORITHM:
Start
1. Declare the variables and read the order of the matrix n
2. Read the stopping criteria er
3. Read the coefficients aim as
Do for i=1 to n
Do for j=1 to n
Read a[i][j]
Repeat for j
Repeat for i
4. Read the coefficients b[i] for i=1 to n
5. Initialize x0[i] = 0 for i=1 to n
6. Set key=0
7. For i=1 to n
Set sum = b[i]
For j=1 to n
If (j not equal to i)
Set sum = sum – a[i][j] * x0[j]
Repeat j
x[i] = sum/a[i][i]
If absolute value of ((x[i] – x0[i]) / x[i]) > er, then
Set key = 1
Set x0[i] = x[i]
Repeat i
8. If key = 1, then
9. 9. Goto step 6
10. Otherwise print results
Stop

CODE:
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

void main()
{
float a[10][10], b[10], x[10], xn[10], epp=0.00001, sum;
int i, j, n, flag;

printf("Enter number of variables: ");


scanf("%d", &n);
printf("Enter the coefficients row-wise:\n");
for(i=0;i<n;i++)
for(j=0;j<n;j++)
scanf("%f", &a[i][j]);
printf("Enter right hand vectors:\n");
for(i=0;i<n;i++)
scanf("%f", &b[i]);
for(i=0;i<n;i++)

13
x[i]=0; //initialize
/* testing of diagonal dominance may be included here from
the program of Gauss-Jacobi's method */
do{
for(i=0;i<n;i++)
{
sum=b[i];
for(j=0;j<n;j++)
{
if(j<i)
sum-=a[i][j]*xn[j];
else if(j>i)
sum-=a[i][j]*x[j];
xn[i]=sum/a[i][j];
}
}
flag=0; // indicates |x[i]-xn[i]|<epp for all i
for(i=0;i<n;i++)
if(fabs(x[i]-xn[i])>epp)
flag=1;
if(flag==1)
for(i=0;i<n;i++)
x[i]=xn[i]; // reset x[i]
}while(flag==1);
printf("Solution is \n");
for(i=0;i<n;i++)
printf("%8.5f ",xn[i]);
}

OUTPUT:

COMMENTS:
In this lab, we learned the iterative process of solving a set of linear algebraic equation using Gauss-Seidel
Method by writing C-codes. Before the start of the process of iteration, the algorithm for partial pivoting
was carried out as given above. Then written codes were tested for different sets of equation. This was
done on the fourth day of the lab.

14

You might also like