Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. double fofx(double input) {
  6. return 1/input - cos(input);
  7. }
  8.  
  9. int main() {
  10. int k = 0;
  11. double a = 4.0;
  12. double b = 6.0;
  13. double x = 0.0;
  14. cout << "k\t\tak\t\tbk\t\txk\t\t" << endl;
  15.  
  16. for (k = 0; k <= 5; k++) {
  17. x = (a + b)/2;
  18.  
  19. cout << k << "\t\t" << a << "\t\t" << b << "\t\t" << x << endl;
  20.  
  21. if (fofx(x) * fofx(a) < 0) {
  22. b = x;
  23. } else {
  24. a = x;
  25. }
  26. }
  27.  
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement