Subscribe Us

Responsive Advertisement

Advertisement

10. Jacobi Method

 

10. Jacobi Method

by ujjal roy



#include<bits/stdc++.h>

using namespace std;

int main()

{

    double x=0,y=0,z=0,x1,y1,z1,e;

    cout<<"Enter Error \n ";

    cin>>e;

    int step=0;

    while(1)

    {

        step++;

        double e1,e2,e3;

        x1=(85-6*y+z)/27.0;

        y1=(72-6*x+2*z)/15.0;

        z1=(110-x-y)/54.0;

        e1=fabs(x1-x);

        e2=fabs(y1-y);

        e3=fabs(z1-z);

        if(e>=e1&&e>=e2&&e>=e3)

        {

            break;

        }

      x=x1;

      y=y1;

      z=z1;

    }

    cout<<step<<endl;

   cout<<"X "<<x1<<"\n";

   cout<<"Y "<<y1<<"\n";

   cout<<"Z "<<z1<<"\n";

    return 0;

}


Post a Comment

0 Comments