Advertisement
newb_ie

A

Oct 28th, 2021
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. #include "bits/stdc++.h"
  2. using namespace std;
  3.  
  4. const int maxN = 1000;
  5. double x[maxN];
  6.  
  7. double get (double x) {
  8. return 3 * x - cos(x) - 1;
  9. }
  10.  
  11. bool check (double dx, double dy) {
  12. string x = to_string(dx);
  13. string y = to_string(dy);
  14. return x == y;
  15. }
  16.  
  17. int main () {
  18. ios::sync_with_stdio(false);
  19. cin.tie(nullptr);
  20. cout.tie(nullptr);
  21. double l = 0.0, r = 10.0;
  22. x[0] = 0.0;
  23. for (int rep = 0; rep <= 70; ++rep) {
  24. double mid = (l + r) / 2;
  25. if (get(mid) >= 0.0) {
  26. r = mid;
  27. x[0] = mid;
  28. } else {
  29. l = mid;
  30. }
  31. }
  32. //x[0] = 0.6;
  33. double pi_not = (1 / 3.0) * (-sin(x[0]));
  34. if (pi_not < 1) {
  35. cout << pi_not << " Is less then " << 1 << '\n';
  36. }
  37. for (int i = 1; i <= 100; ++i) {
  38. x[i] = (cos(x[i - 1]) + 1) / 3.0;
  39. if (check(x[i], x[i - 1])) {
  40. cout << "Iteration : " << i << ' ' << "and Value " << x[i] << '\n';
  41. break;
  42. }
  43. }
  44. }
  45.  
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement