Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _USE_MATH_DEFINES
- #include <iostream>
- #include <cmath>
- using namespace std;
- double GetY(double x)
- {
- //log() - взять натуральный логорифм
- //pow(x,y) возвести x в y степень
- return log(pow(M_E, x)) + 1;
- }
- struct Prym
- {
- public:
- double x1, x2, y;
- double Square()
- {
- return (x2 - x1) * y;
- };
- double GetX2() { return x2; }
- Prym() { x1 = 0; x2 = 0; y = 0; }
- Prym(double x1, double x2, double y)
- {
- this->x1 = x1;
- this->x2 = x2;
- this->y = y;
- }
- };
- double GetStep(double x)
- {
- const float accuracy = 0.001f;
- double step = 1;
- while (true)
- {
- step -= 0.0001;
- if(abs( GetY(x) - GetY(x-step) ) < accuracy)
- {
- break;
- }
- }
- return step;
- }
- int main()
- {
- setlocale(LC_ALL, "rus");
- const float a = 0, b = 1;
- double step;
- double sum;
- double x = a;
- step = GetStep(x);
- Prym pr1 = Prym(x, x + step, GetY(x));
- sum = pr1.Square();
- x += step;
- Prym pr2;
- while (x <= b)
- {
- x += step;
- pr2 = Prym(pr1.GetX2(), x, GetY(x));
- sum += pr2.Square();
- cout << sum << endl;
- pr1 = pr2;
- }
- cout << "Интеграл равен: " << sum;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement