Let’s understand the Gauss-seidel method in numerical analysis and learn how to implement Gauss Seidel method in C programming with an explanation, output, advantages, disadvantages and much more.

#### What is Gauss Seidel Method?

The Gauss Seidel method is an iterative process to solve a square system of multiple linear equations. It also is popularly known as **Liebmann method**.

In an iterative method in numerical analysis, every solution attempt is started with an approximate solution of an equation and iteration is performed until the desired accuracy is obtained.

In Gauss-Seidel method, the most recent values are used in successive iterations. The Gauss-Seidel Method allows the user to control round-off error.

The Gauss Seidel method is very similar to Jacobi method and is called as the **method of successive displacement**.

The Gauss Seidel **convergence criteria** depend upon the following two properties:

- The matrix is diagonally dominant.
- The matrix is symmetrical and positive – definite.

#### Gauss Seidel Method Algorithm

Step 1: Compute value for all the linear equations for Xi Step 2: Initial Array must be available Step 3: Compute each Xi and repeat the above steps Step 4: Make use of the absolute relative approximate error after every step to check if the error occurs within a pre-specified tolerance.

#### Advantages

- Faster iteration process.
- Simple and easy to implement.
- Low on memory requirements.

#### Disadvantages

- Slower rate of convergence.
- Requires a large number of iterations to reach the convergence point.

**Note**: This Gauss Seidel method C Program is compiled with GNU GCC compiler using CodeLite IDE on Microsoft Windows 10 operating system.

#### Method 1: Implement Gauss Seidel Method in C Programming

#include<stdio.h> #include<math.h> int main() { int count, t, limit; float temp, error, a, sum = 0; float matrix[10][10], y[10], allowed_error; printf("\nEnter the Total Number of Equations:\t"); scanf("%d", &limit); printf("Enter Allowed Error:\t"); scanf("%f", &allowed_error); printf("\nEnter the Co-Efficients\n"); for(count = 1; count <= limit; count++) { for(t = 1; t <= limit + 1; t++) { printf("Matrix[%d][%d] = ", count, t); scanf("%f", &matrix[count][t]); } } for(count = 1; count <= limit; count++) { y[count] = 0; } do { a = 0; for(count = 1; count <= limit; count++) { sum = 0; for(t = 1; t <= limit; t++) { if(t != count) { sum = sum + matrix[count][t] * y[t]; } } temp = (matrix[count][limit + 1] - sum) / matrix[count][count]; error = fabs(y[count] - temp); if(error > a) { a = error; } y[count] = temp; printf("\nY[%d]=\t%f", count, y[count]); } printf("\n"); } while(a >= allowed_error); printf("\n\nSolution\n\n"); for(count = 1; count <= limit; count++) { printf("\nY[%d]:\t%f", count, y[count]); } return 0; }

#### Output

#### Method 2: C Program For Gauss Seidel Iterative Method

#include<stdio.h> #define X3(x1, x2) ((7 - 3 * (x1) + (x2)) / 10) #define X1(x2, x3) ((6 - 5 * (x2) + 4 * (x3)) / 10) #define X2(x1, x3) ((9 - 4 * (x1) + (x3)) / 10) int main() { double allowed_error; double x1 = 0, x2 = 0, x3 = 0, y1 = 0, y2 = 0, y3 = 0; int count = 0; printf("Enter value for Allowed Error:\t"); scanf("%lf", &allowed_error); printf("\nx1\t\tx2\t\tx3"); printf("\n%f\t%f\t%f", x1, x2, x3); do { y1 = X1(x2, x3); y2 = X2(y1, x3); y3 = X3(y1, y2); if(fabs(y1 - x1) < allowed_error && fabs(y2 - x2) < allowed_error && fabs(y3 - x3) < allowed_error) { printf("\n\nx1 = %.lf", y1); printf("\nx2 = %.2lf", y2); printf("\nx3 = %.2lf", y3); count = 1; } else { x1 = y1; x2 = y2; x3 = y3; printf("\n%f\t%f\t%f", x1, x2, x3); } }while(count != 1); return 0; }

#### Output

If you have any doubts about the implementation of Gauss Seidel method in C programming, let us know about it in the comment section. Find more about it on **Wikipedia**.

This is too good. Thanks for all the numerical methods c codes.

well can I get algo regarding gauss seidel methid