In the last article about solving the roots of given linear equations, we have discussed Gauss Elimination method. In that method we just go on eliminating one variable and keep on decreasing number of equations. Finally we get only one equation, with only one variable. We put this value in former equations to get values of other roots.

Similarly there is another method for finding the roots of given set of linear equations, this method is known as Gauss Jordan method. This method is same that of Gauss Elimination method with some modifications. In Gauss Jordan method we keep number of equations same as given, only we remove one variable from each equation each time. Thus finally we get same number of equations with only one variable in each equation. Thus we can find out roots of given set of linear equation.

## Gauss Jordan Method with MATLAB & C Program Examples

**Let us consider set of three equations as follows:**

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

**Solution:**

**Step 1):**

Eliminate ‘x’ from 2nd and 3rd equation using 1st equation as follows:

eq.(2) – (a2/a1)*eq.(1) ; eq.(3) – (a3/a1)*eq.(1) ;

When we solve above two equations, we get two new equations in ‘y’ and ‘z’

Write first and these two equations as follows:

a1x+b1y+c1z=d1 …………4) b1’y+c1’z=d1’ …………5) b2’y+c2’z=d2’ …………6)

**Step 2): **

Eliminate ‘y’ from 4th and 6th equation using 5th equation as follows:

eq.(4) – (b1/b1’)*eq.(5) ; eq.(6) – (b2’/b1’)*eq.(5) ;

When we solve above two equations, we get two new equations, write these equations in the following form. (Note that we are writing 5th equation as it is and defining it as 8th equation)

a1”x+c1”=d1” ……………7) b1’y+c1’z=d1’ ……………8) c2”z=d2” ……………9)

Don’t get over exited, here we don’t use value of z from 9th equation directly because it is not an elimination method.

**Step 3): **

Eliminate ‘z’ from 7th and 8th equation using 9th equation as follows:

eq.(7) – (c1”/c2”)*eq.(9) ; eq.(c1’/c2”)*eq.(9);

After solving above two equation, we directly get two new equations contains only one variable each.

Let us discuss Gauss Jordan method by solving one simple set of linear equation.

### Example:

Find roots of following set of linear equations:

x+y+z=9 …………1) 2x-3y+4z=13 …………2) 3x+4y+5z=40 …………3)

**Solution:**

**Step 1): **

Eliminate ‘x’ from 2nd and 3rd equation using 1st equation as follows:

eq.(2) – 2*eq.(1); eq.(3) – 3*eq.(1); x+y+z=9 ……………4) -5y+2z=-5 ……………5) y+2z=13 ……………6)

**Step 2): **

Eliminate ‘y’ from 4th and 6th equation using 5th equation as follows:

eq.(4)+(1/5)*eq.(5) ; eq.(6)+(1/5)*eq.(5) ; x+(7/5)z=8 ……………7) -5y+2z=-5 ……………8) (12/5)z=12 …………9)

**Step 3):**

Eliminate ‘z’ from 7th and 8th equation using 9th equation as follows:

eq.(7)-(7/12)*eq.(9) ; eq.(8) – (5/6)*eq.(9) x=1; -5y=-15 i.e. y=3; Z=5

### Gauss Jordan Method Video Explanation

### Gauss Jordan Method MATLAB Code

### Gauss Jordan Method C Program

/* Gauss Jordan Method C Program */ #include<stdio.h> int main() { int i,j,k,n; float A[20][20],c,x[10]; printf("\nPlease enter the size of matrix: "); scanf("%d",&n); printf("\nPlease enter the elements of augmented matrix row-wise:\n"); for(i=1; i<=n; i++) { for(j=1; j<=(n+1); j++) { printf(" A[%d][%d]:", i,j); scanf("%f",&A[i][j]); } } /* Below for loop is used to find the elements of diagonal matrix */ for(j=1; j<=n; j++) { for(i=1; i<=n; i++) { if(i!=j) { c=A[i][j]/A[j][j]; for(k=1; k<=n+1; k++) { A[i][k]=A[i][k]-c*A[j][k]; } } } } printf("\nThe solution is:\n"); for(i=1; i<=n; i++) { x[i]=A[i][n+1]/A[i][i]; printf("\n x%d=%f\n",i,x[i]); } return(0); }

** You may also like:**

- Jacobi’s iteration method
- Gauss elimination method
- Lagrange interpolation with MATLAB Program
- Simpson’s 3/8th Rule MATLAB Program example
- Simpson’s 1/3rd rule MATLAB Program examples
- MATLAB Programming for Trapezoidal rule with example

I hope you liked this article on Gauss Jordan Method with MATLAB Code and C Program. If you have any queries, please use below comments section for the same. Please like our Facebook page and subscribe to our newsletter for future updates. Have a nice day! tada…