Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "bits/stdc++.h"
- using namespace std;
- const int maxN = 1000;
- double x[maxN];
- double get (double x) {
- return 3 * x - cos(x) - 1;
- }
- bool check (double dx, double dy) {
- string x = to_string(dx);
- string y = to_string(dy);
- return x == y;
- }
- int main () {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- double l = 0.0, r = 10.0;
- x[0] = 0.0;
- for (int rep = 0; rep <= 70; ++rep) {
- double mid = (l + r) / 2;
- if (get(mid) >= 0.0) {
- r = mid;
- x[0] = mid;
- } else {
- l = mid;
- }
- }
- //x[0] = 0.6;
- double pi_not = (1 / 3.0) * (-sin(x[0]));
- if (pi_not < 1) {
- cout << pi_not << " Is less then " << 1 << '\n';
- }
- for (int i = 1; i <= 100; ++i) {
- x[i] = (cos(x[i - 1]) + 1) / 3.0;
- if (check(x[i], x[i - 1])) {
- cout << "Iteration : " << i << ' ' << "and Value " << x[i] << '\n';
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement