Advertisement
Guest User

Untitled

a guest
Feb 19th, 2018
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. #include <iomanip>
  4. #include <locale>
  5. using namespace std;
  6. int fcCounter = 0;
  7. float f(float x) {
  8. ++fcCounter;
  9. return (pow(x, 4) + (-0.1)*atan(4 * x));
  10. }
  11.  
  12. int main() {
  13. float a, b;
  14. float eps; int i = 0;
  15. float x1, x2;
  16. printf("Input a, b, eps\n");
  17. scanf_s("%f %f %f", &a, &b, &eps);
  18. x1 = (a + b - (eps / 2)) / 2;
  19. x2 = (a + b + (eps / 2)) / 2;
  20. printf("i\ta\t x1\t x2\t b\n");
  21. printf("%i\t%.2f %.2f\t %.2f %.2f\n", i, a, x1, x2, b);
  22. while (fabs(b - a) > eps) {
  23. x1 = (a + b - (eps / 2)) / 2;
  24. x2 = (a + b + (eps / 2)) / 2;
  25. if (f(x1) > f(x2))
  26. {
  27. a = x1;
  28. }
  29. else
  30. {
  31. b = x2;
  32. }
  33.  
  34. i++;
  35. printf("%i\t%.2f %.2f\t %.2f %.2f\n", i, a, x1, x2, b);
  36. } //
  37. printf(" x=%f y=%f, fcCounter=%i", (a + b) / 2, f((a + b) / 2), fcCounter);
  38. system("pause"); return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement