-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLAB(4)(+)_Uravn.cpp
More file actions
59 lines (54 loc) · 1.22 KB
/
Copy pathLAB(4)(+)_Uravn.cpp
File metadata and controls
59 lines (54 loc) · 1.22 KB
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
#include <iostream>
#include <cmath>
using namespace std;
double fun2(double x)
{
return x - (x - cos(x)) / (1 + sin(x));
}
double fun(double x)
{
return (x - cos(x));
}
int main()
{
setlocale(LC_ALL, "Russian");
const double e = 0.000001;
double x0, x, a, b, t;
int n = 0;
cout << "Метод простой итерации" << endl;
cout << "Введите переменную X: ";
cin >> x;
x0 = x - 1;
while (abs(x - x0) > e)
{
x0 = x;
x = cos(x0);
n = n + 1;
}
cout << "Корень: " << x << ' ' << "Кол-во шагов: " << n << endl << endl;
n = 0;
cout << "Метод половинного деления" << endl;
cout << "Введите переменные A и B: " << endl;
cin >> a >> b;
do
{
n++;
t = (b + a) / 2;
if (fun(a)*fun(t) > 0) a = t;
else b = t;
} while (abs(a - b) >= e);
x = (a + b) / 2;
cout << "Корень: " << x << ' ' << "Кол-во шагов: " << n << endl << endl;
n = 0;
cout << "Метод Ньютона" << endl;
cout << "Введите переменную X: ";
cin >> x;
do
{
n++;
x0 = x;
x = fun2(x0);
} while (abs(x - x0) >= e);
cout << "Корень: " << x << ' ' << "Кол-во шагов: " << n << endl << endl;
return 0;
}