Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Определение области на плоскости, в которую попадает точка,
- //и площади этой области аналитическим и програмным способом
- //методом криволинейных трапеций (средних прямоугольников)
- //Рекурсия. Передача имен функций в качестве параметров
- #include<iostream>
- #include<math.h>
- #include<cmath>
- #include<locale.h>
- #define M_PI 3.14159265358979323846
- using namespace std;
- typedef double(*TFun)(double);
- double integral(double, double, double, double, TFun, double);
- double ydlya2(double x) { return 2; };
- double ydlya1(double x) { return 1; };
- double ydlyam1(double x) { return -1; };
- double ydlyam2(double x) { return -2; };
- double yupup(double x) {
- return sqrt(1 - (x*x)) + 1;
- }
- double ydownup(double x) {
- return -sqrt(1 - (x*x)) + 1;
- }
- double yupleft(double x) {
- return sqrt(1 - ((x + 1)*(x + 1)));
- }
- double ydownleft(double x) {
- return -sqrt(1 - ((x + 1)*(x + 1)));
- }
- double yupright(double x) {
- return sqrt(1 - ((x - 1)*(x - 1)));
- }
- double ydownright(double x) {
- return -sqrt(1 - ((x - 1)*(x - 1)));
- }
- double yupdown(double x) {
- return sqrt(1 - (x*x)) - 1;
- }
- double ydowndown(double x) {
- return -sqrt(1 - (x*x)) - 1;
- }
- double yupcentral(double x) {
- return sqrt(1 - (x*x));
- }
- double ydowncentral(double x) {
- return -sqrt(1 - (x*x));
- }
- const double eps = 0.00001; //точность вычисления
- const double startStep = 0.001; //начальный шаг вычисления
- int main()
- {
- setlocale(LC_ALL, "Rus");
- int place = 0; //номер области
- double x = 0;
- double y = 0;
- cout << "Введите координаты точки x: ";
- cin >> x;
- cout << "Введите координаты точки y: ";
- cin >> y;
- if ((x*x) + (y - 1)*(y - 1) > 1 && (x - 1)*(x - 1) + (y*y) > 1 && x > -2 && y < 2 && x < 0 && y>0) {
- cout << "Точка в области M1. " << endl;
- place = 1;
- }
- else
- if ((((x*x) + (y*y)) < 1) && (x*x) + (y - 1)*(y - 1) < 1 && x < 0)
- {
- cout << "Точка в области М2. " << endl;
- place = 2;
- }
- else
- if (((x - 1)*(x - 1) + y * y < 1) && (x*x) + (y*y) > 1 && y < 0 && x < 1)
- {
- cout << "Точка в области М3. " << endl;
- place = 3;
- }
- else
- if (((x*x) + (y*y) > 1) && x < 0 && (x*x) + (y + 1)*(y + 1) < 1)
- {
- cout << "Точка в области М4. " << endl;
- place = 4;
- }
- else
- if (y < -1 && (x*x) + (y + 1)*(y + 1) > 1 && x > 0 && x < 2 && y > -2)
- {
- cout << "Точка в области М5. " << endl;
- place = 5;
- }
- else
- cout << "Точка вне выделенных областей";
- cout.precision(8); //число знаков после дес. точки
- switch (place)
- {
- case 1:
- cout << "Формула: S1 = " << 3 - M_PI / 2 << endl;
- cout << "Интеграл: S1 = " << integral(-2, 0, startStep, eps, ydlya2, 0)
- - integral(-2, -1, startStep, eps, yupleft, 0)
- - integral(-1, 0, startStep, eps, yupup, 0) << endl;
- break;
- case 2:
- cout << "Формула: S2 = " << 2 - M_PI / 2 << endl;
- cout << "Интеграл: S2 = " << integral(-1, 1, startStep, eps, ydlya1, 0)
- - integral(-1, 0, startStep, eps, yupleft, 0)
- - integral(0, 1, startStep, eps, yupright, 0) << endl;
- break;
- case 3:
- cout << "Формула: S3 = " << 1 - 2 * (1 - M_PI / 4) - (sqrt(3) / 2 + M_PI / 3 - M_PI / 4 - 1) << endl;
- cout << "Интеграл: S3 = " << integral(-0.5, 0, startStep, eps, ydownleft, 0)
- + integral(-sqrt(3) / 2, -0.5, startStep, eps, ydowncentral, 0)
- - integral(-sqrt(3) / 2, 0, startStep, eps, yupdown 0);
- break;
- case 4:
- cout << "Формула: S4 = " << 1 << endl;
- cout << "Интеграл: S4 = " << integral(1, 2, startStep, eps, ydownright, 0)
- + integral(0, 1, startStep, eps, yupdown, 0) << endl;
- break;
- case 5:
- cout << "Формула: S5 = " << 2 - M_PI / 4 << endl;
- cout << "Интеграл: S5 = " << integral(0, 2, startStep, eps, ydlya2, 0) - integral(0, 1, startStep, eps, ydlya1, 0)
- - integral(0, 1, startStep, eps, ydowndown, 0);
- } system("pause"); return 0;
- }
- //нахождение определенного интеграла методом левых прямоугольников
- double integral(double begin, double end, double shag, double eps, TFun fun, double previousArea)
- {
- double currentArea = 0;
- size_t countSteps = (end - begin) / shag;
- double sumOfY = 0;
- for (int i = 0; i < countSteps; i++) {
- double currentX = begin + shag * i;
- sumOfY += (fabs(fun(currentX))); // sumOfY += (fabs(fun(begin + shag * i)));
- }
- currentArea = sumOfY * shag;
- if (fabs(currentArea - previousArea) > eps) //разница между интегралом с текущим шагом и интегралом с шагом в двое
- return integral(begin, end, shag / 2, eps, fun, currentArea);
- return currentArea;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement