Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. #define _USE_MATH_DEFINES
  2. #include <iostream>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. double GetY(double x)
  8. {
  9.     //log() - взять натуральный логорифм
  10.     //pow(x,y) возвести x в y степень
  11.     return log(pow(M_E, x)) + 1;
  12. }
  13.  
  14. struct Prym
  15. {
  16.     public:
  17.    
  18.         double x1, x2, y;
  19.         double Square()
  20.         {
  21.             return (x2 - x1) * y;
  22.         };
  23.    
  24.         double GetX2() { return x2; }
  25.    
  26.         Prym() { x1 = 0; x2 = 0; y = 0; }
  27.    
  28.         Prym(double x1, double x2, double y)
  29.         {
  30.             this->x1 = x1;
  31.             this->x2 = x2;
  32.             this->y = y;
  33.         }
  34. };
  35.  
  36. double GetStep(double x)
  37. {
  38.     const float accuracy = 0.001f;
  39.     double step = 1;
  40.  
  41.     while (true)
  42.     {
  43.         step -= 0.0001;
  44.         if(abs( GetY(x) - GetY(x-step) ) < accuracy)
  45.         {
  46.             break;
  47.         }
  48.     }
  49.  
  50.     return step;
  51. }
  52.  
  53. int main()
  54. {
  55.     setlocale(LC_ALL, "rus");
  56.  
  57.     const float a = 0, b = 1;
  58.     double step;
  59.  
  60.     double sum;
  61.     double x = a;
  62.     step = GetStep(x);
  63.     Prym pr1 = Prym(x, x + step, GetY(x));
  64.     sum = pr1.Square();
  65.     x += step;
  66.     Prym pr2;
  67.  
  68.     while (x <= b)
  69.     {
  70.         x += step;
  71.         pr2 = Prym(pr1.GetX2(), x, GetY(x));
  72.         sum += pr2.Square();
  73.         cout << sum << endl;
  74.         pr1 = pr2;
  75.     }
  76.     cout << "Интеграл равен: " << sum;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement