# Gauss Seidel Method MATLAB Program & Algorithm

We have studied in the last article that, the preceding methods of solving simultaneous linear equations are known as direct methods as they yield the exact solution. On the other hand, an iterative method is that in which we start from an approximation to the true solution and obtain better and better approximation from a computation cycle repeated as often as may be necessary for achieving the desired accuracy. Simple iteration methods can be devised for systems in which the coefficient of leading diagonal is large compared to others.

In the last article about solving roots of given simultaneous equations, we have studied Jacobi’s iterative method. Similarly, there is another method for solving roots of simultaneous equations which is called as Gauss-Seidel Iterative Method. After that, we will see MATLAB program on how to find roots of simultaneous equations using Gauss-Seidel Method.

Let us consider set of simultaneous equations as follows:

• a1x+b1y+c1z=d1…………………1)
• a2x+b2y+c2z=d2…………………1)
• a3x+b3y+c3z=d3…………………1)

We then solve above equation for x, y and z respectively. Then the system can be written in the form:

• x = (k1) – (l1)y – (m1)z…………..2)
• y = (k2) – (l2)x – (m2)z…………….2)
• z = (k3) – (l3)x – (m3)y…………….2)

Gauss-Seidel Method is a modification of Jacobi’s iteration method as before we starts with initial approximations, i.e. x0=y0=z0=0 for x, y and z respectively.

Substituting y=y0, z=z0 in the equation x1=k1, then putting x=x1, z=z0 in the second of equation (2) i.e.

• (y1) = (k2) – (l2)x1 – (m2)z0

Substituting x=x1, y=y1 in the third of equation (2) i.e.

• (z1) = (k3) – (l3)x1 – (m3)y1  and so on.

As soon as a new approximation for an unknown is found it is immediately used in the next step. This process is then repeated till the desired degree of accuracy is obtained.

Let us discuss Gauss-Seidel method by solving one simple example.

## Example

Find the roots of following simultaneous equations using the Gauss-Seidel method.

20x+y-2z=17…………..1)

3x+20y-z=-18…………..1)

2x-3y+20z=25…………..1)

## Solution

Let us write the given equation in the form as:

x = (1/20)(17-y+2z)……………..2)

y = (1/20)(-18-3x+z)…………….2)

z = (1/20)(25-2x+3y)……………2)

we start approximation by x0=y0=z0=0.

Substituting y=y0 and z=z0 in right hand side of first of equation (2)

X1 = 17/20=0.85

In second of equation second put x=x1 and z=z0

Y1 = (1/20)(-18-3*0.85) = -1.0275

Put x=x1, y=y1 in third of equation (2)

Z1 = (1/20)(25-2*0.85+3*-1.0275) = 1.011

Similarly we get,

x2=1.002; y2 =-0.9998; z2 =0.9998

x3 =1.0000; y3 =-1.0000; z3 =1.0000

x4 =1.0000; y4 =-1.0000; z4 =1.0000

Now it is sufficient. If you observe above two sets of roots, they are almost same.

Hence the roots of given simultaneous equations using Gauss-Seidel Method are:

x=1;  y = -1;  z=1

## MATLAB program for Gauss-Seidel Method MATLAB code for Gauss-Seidel method

If you like this article, please share it with your friends and like or facebook page for future updates. Subscribe to our newsletter to get notifications about our updates via email. If you have any queries, feel free to ask in the comments section below. Have a nice day!

## One thought on “Gauss Seidel Method MATLAB Program & Algorithm”

1. kiran says:

Can you make a program for solving the same problem by using Newton Raphson method?