Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- int n = 3;
- int main()
- {
- double arr[3][3] = { {4,-1,1},{2,6,-3},{1,2,-3} };
- double b[3] = { 4,7,0 };
- double e = 0.001;
- int M = 5, l = 1, k = 1;
- double xi[3] = { 0,0,0 };
- int r = 0;
- double d = 0;
- while (l < 0)
- {
- for (int i = 1; i < n; i++)
- {
- int s = 0;
- for (int j = 0; j < i - 1; j++)
- {
- s += arr[i][j];
- }
- for (int j = 0; j < n; j++)
- {
- s += arr[i][j];
- }
- double x = (b[i] - s) / arr[i][r];
- d = abs(b[i] - xi[i]);
- xi[i] = x;
- l++;
- }
- if (d <= e)
- {
- l = 1;
- }
- else if(k = M)
- {
- l = 2;
- }
- else
- {
- k += 1;
- }
- }
- for (int i = 1; i <= n; i++)
- cout << "x[" << i << "]=" << xi[i] << " " << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement