Advertisement
SomeBody_Aplle

Untitled

Jan 12th, 2022
50
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. int n = 3;
  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 = 5, l = 1, k = 1;
  14.     double xi[3] = { 0,0,0 };
  15.     int r = 0;
  16.     double d = 0;
  17.     while (l < 0)
  18.     {
  19.         for (int i = 1; i < n; i++)
  20.         {
  21.             int s = 0;
  22.             for (int j = 0; j < i - 1; j++)
  23.             {
  24.                 s += arr[i][j];
  25.             }
  26.             for (int j = 0; j < n; j++)
  27.             {
  28.                 s += arr[i][j];
  29.             }
  30.             double x = (b[i] - s) / arr[i][r];
  31.             d = abs(b[i] - xi[i]);
  32.             xi[i] = x;
  33.             l++;
  34.         }
  35.         if (d <= e)
  36.         {
  37.             l = 1;
  38.         }
  39.         else if(k = M)
  40.         {
  41.             l = 2;
  42.         }
  43.         else
  44.         {
  45.             k += 1;
  46.         }
  47.     }
  48.     for (int i = 1; i <= n; i++)
  49.         cout << "x[" << i << "]=" << xi[i] << " " << endl;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement