The direct methods such as Cramer’s rule, matrix inversion method, Gauss Elimination method, etc. for the solution of simultaneous algebraic equations yield the solution after a certain amount of fixed computation. So, direct method of solution takes longer time to get the solution.
On the other hand, in case of iterative methods such as Gauss Jacobi and Gauss-Seidel iteration method, we start with an approximate solution of equation and iterate it till we don’t get the result of desired accuracy. Here is source code for Gauss-Seidel in C with working procedure and sample output.
The manual computation iterative method is quite lengthy. But, the program in high level languages run fast and effectively. This C program for Gauss-Seidel method has been designed for the solution of linear simultaneous algebraic equations based on the principle of iteration.
In this program, a certain approximate value of solution is assumed and further calculations are done based on the result of assumed approximate solution.
The program for Gauss-Seidel method in C works by following the steps listed below:
- When the program is executed, first of all it asks for the value of elements of the augmented matrix row wise.
- Then, the program asks for allowed error and maximum number of iteration to which the calculations are to be done. The number of iterations required depends upon the degree of accuracy.
- The program assumes initial or approximate solution as y=0 and z=0 and new value of x which is used to calculate new values of y and z using the following expressions:
x= 1/a1 ( d1-b1y-c1z)
y=1/b2 ( d2-a2x-c2z)
z=1/c3 ( d3-a3x-b3y)
- The iteration process is continued until a desired degree of accuracy is not met.
Source Code for Gauss-Seidel Method in C:
#define X 2
float x[X][X+1],a[X], ae, max,t,s,e;
puts(" Eneter the elemrnts of augmented matrix rowwise\n");
printf(" Eneter the allowed error and maximum number of iteration: ");
printf(" Converses in %3d iteration\n", r);
In this C language code for Gauss-Seidel method, the value of order of square matrix has been defined as a macro of value 2 which can be changed to any order in the source code.
Also, the elements of augmented matrix have been defined as array so that a number of values can be stored under a single variable name. The program can be used effectively to solve linear simultaneous algebraic equation though easy, accurate and convenient way.