Haval1

jacobi method

Jan 9th, 2019
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. // jacobi method.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "iostream"
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     int a[3][4], c[3][4], i, j, max, n, s;
  11.     for (i = 0;i < 3;i++)
  12.         for (j = 0;j < 4;j++) {
  13.             cout << "[" << i + 1 << "][" << j + 1 << "] : ";
  14.             cin >> a[i][j];
  15.         }
  16.     for (n = 0;n < 3;n++) {
  17.         max = -9999;
  18.         for(i=0;i<3;i++)
  19.             if (a[i][n] > max) {
  20.                 max = a[i][n];
  21.                 s = i;
  22.             }
  23.         for (j = 0;j < 4;j++)
  24.             c[n][j] = a[s][j];
  25.     }
  26.     for (i = 0;i < 3;i++) {
  27.         for (j = 0;j < 4;j++) {
  28.             cout << c[i][j] << "  ";
  29.         }
  30.         cout << endl;
  31.     }
  32.     float x1, x2, x3, b1, b2, b3;
  33.     b1 = b2 = b3 = 0;
  34.     for (n = 0;n < 6;n++) {
  35.         x1 = (c[0][3] - b2*c[0][1] - b3*c[0][2]) / c[0][0];
  36.         x2 = (c[01][3] - b1*c[1][0] - b3*c[1][2]) / c[1][1];
  37.         x3 = (c[2][3] - b1*c[2][0] - b2*c[2][1]) / c[2][2];
  38.         b1 = x1;
  39.         b2 = x2;
  40.         b3 = x3;
  41.     }
  42.     cout << "x1 = " << x1 << endl << "x2 = " << x2 << endl << "x3 = " << x3 << endl;
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment