Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #include"stdafx.h"
  2. #include <iostream>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. double F(double x) {
  8. return (pow(x, 4) - 13 * pow(x, 2) + 36 - (1 / x));
  9. }
  10.  
  11. double BISECT(double Left, double Right, double Eps, int &N)
  12. {
  13. double E = fabs(Eps)*2.0;
  14. double FLeft = F(Left);
  15. double FRight = F(Right);
  16. double X = (Left + Right) / 2.0;
  17. double Y;
  18. if (FLeft*FRight>0.0) { puts("Interval\n"); exit(1); }
  19. if (Eps <= 0.0) { puts("Tochnost\n"); exit(1); }
  20. N = 0;
  21. if (FLeft == 0.0) return Left;
  22. if (FRight == 0.0) return Right;
  23. while ((Right - Left) >= E)
  24. {
  25. X = 0.5*(Right + Left); /* âû÷èñëåíèå ñåðåäèíû îòðåçêà */
  26. Y = F(X);
  27. if (Y == 0.0) return (X);
  28. if (Y*FLeft < 0.0)
  29. Right = X;
  30. else
  31. {
  32. Left = X; FLeft = Y;
  33. }
  34. N++;
  35. };
  36. return(X);
  37. }
  38.  
  39. double Round(double X, double Delta)
  40. {
  41. if (Delta <= 1E-9) {
  42. puts("tochnost");exit(1);}
  43. if (X>0.0) return (Delta*(long((X / Delta) + 0.5)));
  44. else return (Delta*(long((X / Delta) - 0.5)));
  45. }
  46.  
  47. int main() {
  48. int N=0;
  49. cout <<BISECT(0.0, 0.03, 0.0001, N)<<endl;
  50. cout << N;
  51. return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement