Advertisement
Guest User

Untitled

a guest
Dec 20th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <string>
  4. #include <iostream>
  5. #include <cmath>
  6.  
  7.  
  8. using namespace std;
  9.  
  10. double function(double a, double b, double x) {
  11. double res;
  12. res = 1 / x - log(a*x + b);
  13. return res;
  14. }
  15.  
  16.  
  17. double HalfDivisionMethod(double xl, double xr, double eps, double a, double b) {
  18. double x = (xl + xr) / 2;
  19. if (abs(function(a, b, x)) < eps) return x;
  20. double fl = function(a, b, xl);
  21. double fx = function(a, b, x);
  22. if (fl*fx < 0) {
  23. cout <<"x = "<< x <<endl;
  24. cout << "fl = " << fl << endl;
  25. cout << "fx = " << fx << endl;
  26. cout << "xl = " << xl << endl;
  27. cout << "xr = " << xr << endl;
  28. cout << "Идем влево" << endl<<endl;
  29.  
  30. HalfDivisionMethod(xl, x, eps, a, b);
  31.  
  32. }
  33. else {
  34. cout << "x = " << x << endl;
  35. cout << "fl = " << fl << endl;
  36. cout << "fx = " << fx << endl;
  37. cout << "xl = " << xl << endl;
  38. cout << "xr = " << xr << endl;
  39. cout << "Идем вправо" << endl << endl;
  40. HalfDivisionMethod(x, xr, eps, a, b);
  41. }
  42.  
  43.  
  44. }
  45. int main()
  46. {
  47. setlocale(LC_ALL, "Rus");
  48. cout << "Hello, world!";
  49. cout << HalfDivisionMethod(0.1, 1, 0.00001, 3, 5);
  50. int a;
  51. cin >> a;
  52. return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement