-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
79 lines (60 loc) · 1.92 KB
/
main.cpp
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "fixed_point_iteration.hpp"
#include "newton_iteration.hpp"
////////////////////////////////////////
LD func(const LD& x) {
return (x*std::pow(2L, x) - 1.0L);
}
constexpr LD eq_answer = 0.6411857445049859845L;
LD proizv(const LD& x) {
return (std::log(2)*x*std::pow(2L, x) + std::pow(2L, x));
}
//////////////////////////////////////////
//x=f(x)
vector vector_f(const vector& x) {
vector ret(2);
ret[0] = std::cos(x[1]) + 0.85L;
ret[1] = std::sin(x[0]) - 1.32L;
return ret;
}
//F(x)=0
vector vector_F(const vector& x) {
vector ret(2);
ret[0] = -x[0] + std::cos(x[1]) + 0.85L;
ret[1] = -x[1] + std::sin(x[0]) - 1.32L;
return ret;
}
matrix matrixJ(const vector& x) {
matrix ret(2, 2);
ret(0, 0) = -1;
ret(0, 1) = std::sin(x[1]);
ret(1, 0) = -std::cos(x[0]);
ret(1, 1) = -1;
ret /= (1 + std::sin(x[1])*std::cos(x[0]));
return ret;
}
const vector sys_answer(2);
////////////////////////////////
int main() {
{
vector &just = const_cast<vector&>(sys_answer);
just[0] = 1.791338609964243133L;
just[1] = -0.3442210364010110309L;
}
std::ofstream fin;
fin << std::setprecision(max_precision);
std::cout << std::setprecision(max_precision);
//equation part
fin.open("dataEQFixedPoint.csv");
std::cout << FixedPointIteration(func, 0.5L, 0.0L, std::make_pair(eq_answer, std::ref(fin))) << std::endl;
fin.close();
fin.open("dataEQNewton.csv");
std::cout << NewtonMethod(func, proizv, 0.0L, std::make_pair(eq_answer, std::ref(fin))) << std::endl;
fin.close();
//system of equations part
fin.open("dataSYSFixedPoint.csv");
std::cout << FixedPointIteration(vector_f, zero_vector(2), sys_answer, std::ref(fin)) << std::endl;
fin.close();
fin.open("dataSYSNewton.csv");
std::cout << NewtonMethod(vector_F, matrixJ, zero_vector(2), sys_answer, std::ref(fin)) << std::endl;
fin.close();
}