Advertisement
SomeBody_Aplle

Untitled

Jan 12th, 2022
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3.  
  4. using namespace std;
  5.  
  6.  
  7.  
  8. int main()
  9. {
  10.     double arr[3][3] = { {4,-1,1},{2,6,-3},{1,2,-3} };
  11.     double b[3] = { 4,7,0 };
  12.     double e = 0.001;
  13.     int M = 100, l = 0, k = 1;
  14.     int n = 3;
  15.     double xi[3] = { 0,0,0 };
  16.     int r = 0;
  17.     double d = 0;
  18.     while (l <= 0)
  19.     {
  20.         for (int i = 1; i < n; i++)
  21.         {
  22.             int s = 0;
  23.             for (int j = 0; j < i - 1; j++)
  24.             {
  25.                 s += arr[i][j];
  26.             }
  27.             for (int j = 0; j < n; j++)
  28.             {
  29.                 s += arr[i][j];
  30.             }
  31.             double x = (b[i] - s) / arr[i][r];
  32.             d = abs(x - xi[i]);
  33.             xi[i] = x;
  34.             r++;
  35.         }
  36.         if (d <= e)
  37.         {
  38.             l = 1;
  39.         }
  40.         else if(k = M)
  41.         {
  42.             l = 2;
  43.         }
  44.         else
  45.         {
  46.             k += 1;
  47.         }
  48.     }
  49.     for (int i = 1; i <= n; i++)
  50.         cout << "x[" << i << "]=" << xi[i] << " " << endl;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement