Gauss Jacobi Method in C

In numerical linear algebra, the Jacobi method is an algorithm for determining the solutions of a diagonally dominant system of linear equations. Each diagonal element is solved for, and an approximate value is plugged in. The process is then iterated until it converges. This algorithm is a stripped-down version of the Jacobi transformation method of matrix diagonalization. The method is named after Carl Gustav Jacob Jacobi.

Equation 1: 4-2y-3z

Equation 2: 8-5x-7z = 6

Equation 3: 3-9x-y = 2

Program of Gauss Jacobi in C


   #include<stdio.h>
   #include<conio.h>
   #include<math.h>
   
   float fx(float y,float z)
   {
    float x1; x1=4-2*y-3*z;
    return x1;
   }

   float fy(float x,float z)
   {
    float y1;
    y1=(8-5*x-7*z)/6;
    return y1;
   }

   float fz(float x,float y)
   {
    float z1;
    z1=(3-9*x-y)/2;
    return z1;
   }

   void main()
   {
    int i,j,n;
    float a1,b1,c1;
    float a,b,c;
    float ar[3][4],x[3];
    clrscr();
    printf("Enter the no. of Iteration : ");
    scanf("%d",&n);
    printf("Enter The initial value : ");
    scanf("%f %f %f",&a,&b,&c);
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            a1=fx(b,c);
            b1=fy(a,c);
            c1=fz(a,b);
            a=a1;
            b=b1;
            c=c1;
        }
    }
    printf("a1 = %f\n a2 = %f\n a3 = %f",a1,b1,c1);
    
    getch();
}     
  

Output gauss jacobi method

Watch Tutorial Video on YouTube

Watch and Subscribe Now

Post Your Comment