Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- using namespace std;
- int main()
- {
- setlocale(LC_ALL, "Russian");
- double ebs;
- int n;
- double arr[100][100];
- cout << "Введите размер матрицы" << endl;
- cin >> n;
- cout << "Введите матрицу" << endl;
- for (int i = 0; i < n; i++) {
- for (int j = 0; j <= n; j++) {
- cin >> arr[i][j];
- }
- }
- cout << "Введите максимальную погрешность " << endl;
- cin >> ebs;
- for (int i = 0; i < n; i++) {
- int pos = 0;
- for (int j = 0; j < n; j++) {
- if (arr[pos][i] < arr[j][i]) {
- pos = j;
- }
- }
- double z[100];
- for (int j = 0; j <= n; j++) {
- z[j] = arr[i][j];
- arr[i][j] = arr[pos][j];
- arr[pos][j] = z[j];
- }
- }
- cout << endl;
- for (int i = 0; i < n; i++) {
- for (int j = 0; j <= n; j++) {
- cout << arr[i][j] << " ";
- }
- cout << endl;
- }
- double x[100];
- double xxx[100];
- bool z;
- int k = 0;
- for (int i = 0; i < n; i++) xxx[i] = 0;
- do{
- k++;
- z = false;
- for (int i = 0; i < n; i++) {
- x[i] = arr[i][n];
- for (int j = 0; j < n; j++) {
- if (j != i) {
- x[i] -= arr[i][j] * xxx[j];
- }
- }
- x[i] /= arr[i][i];
- if (fabs(xxx[i] - x[i]) > ebs) {
- z = true;
- }
- }
- for (int j = 0; j < n; j++) {
- xxx[j] = x[j];
- }
- } while (z);
- for (int j = 0; j < n; j++) {
- cout <<"x"<<j+1<<" = "<< xxx[j] << endl;
- }
- cout << "Количество итераций " << k;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement