Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // gaus.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <conio.h>
- #include "atlstr.h"
- #include <fstream>
- #include <windows.h>
- #define eps 0.0001 //точность
- #define N 10000 //размер матрицы
- using namespace std;
- // Условие сходимости
- bool converge(double *xk, double* xkp)
- {
- for (int i = 0; i < 4; i++)
- {
- if (fabs(xk[i]-xkp[i]) >=eps)
- return false;
- }
- return true;
- }
- void main(void)
- {
- /*
- Ход метода, где:
- a[n][n] - Матрица коэффициентов
- x[n] - Вектор текущего решения
- */
- cout << " Size matrix " << N;
- char a[N][N];
- double x[N];
- double p[N];
- char b[N];
- // cout << " Enter matrix ";
- ifstream input_file("D:/A.txt"); //открываем файл
- if (!input_file) cout << " Error. \n";
- int i=0;
- int j=0;
- while (!input_file.eof())
- {
- input_file >> a[i][j];
- cout << a[i][j];
- if (input_file != " ") {j++;}
- if (j==N) {i++;j=0;}
- }
- input_file.close();
- ifstream input_file1("D:/b.txt");
- if (!input_file1) cout << " Error. \n";
- int k =0;
- while (!input_file.eof())
- {
- input_file >> b[k];
- k++;
- }
- input_file1.close();
- do
- {
- for(int i = 0; i < N; i++)
- {
- double var = 0;
- for(int j = 0; j < N; j++)
- if(j != i) var += (a[i][j]*x[j]);
- p[i] = x[i];
- x[i]=(b[i] - var)/a[i][i];
- }
- }
- while(!converge(x,p));
- cout << "Answer ";
- for(int t=0;t<N;t++)
- {
- cout << x[t] << "; ";
- }
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement