-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
35 lines (32 loc) · 805 Bytes
/
main.cpp
File metadata and controls
35 lines (32 loc) · 805 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "Cmatrix.h"
#include "time.h"
#include <random>
#include <profileapi.h>
using namespace std;
Matrix NewtonInvert(const Matrix& A, int stepsCount, double threshold = 0)
{
Matrix cur = T(A) / (norm(A, "1") * norm (A, "inf"));
for (int i = 0; i < stepsCount; i++)
{
cur = 2 * cur - cur * A * cur;
if (norm(A * cur - E(A.h), "sum") < threshold)
break;
}
return cur;
}
int main()
{
int size = 5;
std::vector<cl_float> A_data(size * size);
srand(time(NULL));
for (int i = 0; i < A_data.size(); i++)
{
A_data[i] = rand();
}
Matrix A(A_data, size);
std::ofstream fout("test.txt");
fout << A << '\n';
Matrix A_inv = NewtonInvert(A, 150000, 1);
fout << A_inv << '\n';
fout << A * A_inv << '\n';
}