• API
• FAQ
• Tools
• Archive
SHARE
TWEET # Untitled a guest Apr 9th, 2020 167 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
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.     //return 5;
13. }
14.
15. struct Prym
16. {
17.     public:
18.
19.         double x1, x2, y;
20.         double Square()
21.         {
22.             return (x2 - x1) * y;
23.         };
24.
25.         double GetX2() { return x2; }
26.
27.         Prym() { x1 = 0; x2 = 0; y = 0; }
28.
29.         Prym(double x1, double x2, double y)
30.         {
31.             this->x1 = x1;
32.             this->x2 = x2;
33.             this->y = y;
34.         }
35. };
36.
37. double GetStep(double x)
38. {
39.     const float accuracy = 0.001f;
40.     double step = 0;
41.
42.     while (true)
43.     {
44.         step += 0.001;
45.         //cout << step << endl;
46.         if(abs( GetY(x) - GetY(x + step) ) < accuracy)
47.         {
48.             break;
49.         }
50.     }
51.
52.     return step;
53. }
54.
55. int main()
56. {
57.     setlocale(LC_ALL, "rus");
58.
59.     const float a = 0, b = 1;
60.     double step;
61.
62.     double sum;
63.     double x = a;
64.     step = GetStep(x);
65.     Prym pr1 = Prym(x, x + step, GetY(x));
66.     sum = pr1.Square();
67.     x += step;
68.     Prym pr2;
69.
70.     while (true)
71.     {
72.         step = GetStep(x);
73.         if (x + step <= b)
74.         {
75.             x += step;
76.             pr2 = Prym(pr1.GetX2(), x, GetY(x));
77.             sum += pr2.Square();
78.             //cout << sum << endl;
79.             pr1 = pr2;
80.         }
81.         else
82.             break;
83.     }
84.
85.     cout << "Интеграл равен: " << sum;
86. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Top