These codes are tested in Dev C++ and are error free. If any error occurs, comment below. Other programs will be uploaded as soon as possible.
Thank you! :)

Friday, April 15, 2016

Jacobi Iteration Method

Equations:
2x1 - x2 + x3 = 5
3x1 - 5x2 + 2x3 = 15
2x1 + x2 + 4x3 = 8

Program:

#include<iostream.h>
#include<conio.h>
#define f(x) (5 - x2 - x3)/2
#define g(x) (15 - 3*x1 - 2*x3)/5
#define h(x) (8 - 2*x1 - x2)/4

int main()
{
    float x1, x2, x3, a, b, c;
    int i, n;
    cout << "How many iterations do you want? : " ;
    cin >> n;
    for(i=0; i<n; i++)
    {
          a = f(i);
          b = g(i);
          c = h(i);
          x1 = a;
          x2 = b;
          x3 = c;
          cout << "For i = " << i << endl;
          cout << "x1 = " << x1 << endl << "x2 = " << x2 << endl << "x3 = " << x3 << endl << endl << endl;
       
          }
          cout << "The process can be continued till the values of x reach a desired level of "<<endl << "accuracy. " ;
getch();
return 0;
}



1 comment:

If you have any problem, please leave your message here.