Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include <math.h>
- using namespace std;
- double MyCos(double, double);
- double fact(int);
- int OneP(int);
- int main()
- {
- setlocale(LC_ALL, "ru");
- double eps, d, x, x_start, x_end, dx, x_ideal;// невязка, погрешность - остановка расчета, начальный х, конечный х,
- //шаг вычисления, х для вычисления значений различной точностью
- while (true)
- {
- cout << "Введите точность эпсилон: ";
- cin >> eps;
- if (eps <= 0)
- {
- cout << "Точность должна быть вещественным положительным числом" << endl;
- system("pause");
- return 0;
- }
- cout << "Введите начальный x_start: ";
- cin >> x_start;
- x = x_start;
- cout << "Введите конечный x_end: ";
- cin >> x_end;
- cout << "Введите интервал delta_x: ";
- cin >> dx;
- if (dx <= 0 || eps < 0)
- {
- cout << "Введите верные данные" << endl;
- system("pause");
- system("cls");
- }
- else if (x_start >= x_end)
- {
- printf(" ______________ ___________________ ____________________ ______________ n");
- printf("|_______x______|___MyFunction(x)___|_____x*cos(3*x)_____|_______d______|n");
- printf("| | | | |n");
- x <= x_end + pow(10, -15);////////------
- double MC = MyCos(x, eps) * MyCos(x, eps);
- double XD = x * cos(3 * x) * x * cos(3 * x);
- d = sqrt(fabs(MC - XD));////////////////////////////////////////////////////////
- printf("| %10.6f | %15.10f | %15.10f | %f |n", x, MyCos(x, eps), x*cos(3 * x), d);
- printf("|______________|___________________|____________________|______________|n");
- break;
- }
- else
- {
- printf(" ______________ ___________________ ____________________ ______________ n");
- printf("|_______x______|___MyFunction(x)___|_____x*cos(3*x)_____|_______d______|n");
- printf("| | | | |n");
- for (x; x <= x_end + pow(10, -15); x = x + dx)//шаг.
- {
- double MC = MyCos(x, eps) * MyCos(x, eps);
- double XD = x * cos(3 * x) * x * cos(3 * x);
- d = sqrt(fabs(MC - XD));
- //d = sqrt(fabs(MyCos(x, eps) - x * cos(3 * x)));///////////////////////////////////////////////////
- printf("| %10.6f | %15.10f | %15.10f | %f |n", x, MyCos(x, eps), x*cos(3 * x), d);
- }
- printf("|______________|___________________|____________________|______________|n");
- break;
- }
- }
- cout << "Введите x_ideal" << endl;
- cin >> x_ideal;
- printf(" _____________ ___________________ ____________________ ______________ n");
- printf("|______eps____|___MyFunction(x)___|_____x*cos(3*x)_____|_______d______|n");
- printf("| | | | |n");
- for (int i = 1; i <= 7; i++)
- {
- double e = pow(0.1, i);
- double MC = MyCos(x_ideal, e) * MyCos(x_ideal, e);
- double XD = x_ideal * cos(3 * x_ideal) * x_ideal * cos(3 * x_ideal);
- //d = sqrt(fabs(MyCos(x_ideal, e) - x_ideal * cos(3 * x_ideal)));
- //while (fabsl(MyCos - (x_ideal * cos(3 * x_ideal))) >= eps);
- d = sqrt(fabs(MC - XD));
- printf("| %9.7f | %15.10f | %15.10f | %f |n", e, MyCos(x_ideal, e), x_ideal*cos(3 * x_ideal), d);
- }
- printf("|_____________|___________________|____________________|______________|n");
- system("pause");
- return 0;
- }
- int OneP(int q)
- {
- int a = -1;
- for (int w = 0; w < q; w++)
- {
- a = (-1) * a;
- }
- return a;
- }
- double fact(int n)
- {
- if (n == 0)
- {
- return 1;
- }
- if (n > 0)
- {
- return n * fact(n - 1);
- }
- }
- double MyCos(double x, double eps)
- {
- double sum = 0, a;
- for (int k = 0; fabs(OneP(k + 1) * pow(3, 2 * k) * pow(x, 2 * k + 1) / fact(2 * k) + OneP(k) * pow(3, 2 * k + 2) * pow(x, 2 * k + 3) / fact(2 * k + 2)) > eps; k++)
- {
- a = OneP(k + 1) * pow(3, 2 * k) * pow(x, 2 * k + 1) / fact(2 * k);
- sum = sum + a;
- }
- return sum;
- }`#include "pch.h"
- #include <iostream>
- #include <math.h>
- using namespace std;
- double MyCos(double, double);
- double fact(int);
- int OneP(int);
- int main()
- {
- setlocale(LC_ALL, "ru");
- double eps, d, x, x_start, x_end, dx, x_ideal;// невязка, погрешность - остановка расчета, начальный х, конечный х,
- //шаг вычисления, х для вычисления значений различной точностью
- while (true)
- {
- cout << "Введите точность эпсилон: ";
- cin >> eps;
- if (eps <= 0)
- {
- cout << "Точность должна быть вещественным положительным числом" << endl;
- system("pause");
- return 0;
- }
- cout << "Введите начальный x_start: ";
- cin >> x_start;
- x = x_start;
- cout << "Введите конечный x_end: ";
- cin >> x_end;
- cout << "Введите интервал delta_x: ";
- cin >> dx;
- if (dx <= 0 || eps < 0)
- {
- cout << "Введите верные данные" << endl;
- system("pause");
- system("cls");
- }
- else if (x_start >= x_end)
- {
- printf(" ______________ ___________________ ____________________ ______________ n");
- printf("|_______x______|___MyFunction(x)___|_____x*cos(3*x)_____|_______d______|n");
- printf("| | | | |n");
- x <= x_end + pow(10, -15);////////------
- double MC = MyCos(x, eps) * MyCos(x, eps);
- double XD = x * cos(3 * x) * x * cos(3 * x);
- d = sqrt(fabs(MC - XD));////////////////////////////////////////////////////////
- printf("| %10.6f | %15.10f | %15.10f | %f |n", x, MyCos(x, eps), x*cos(3 * x), d);
- printf("|______________|___________________|____________________|______________|n");
- break;
- }
- else
- {
- printf(" ______________ ___________________ ____________________ ______________ n");
- printf("|_______x______|___MyFunction(x)___|_____x*cos(3*x)_____|_______d______|n");
- printf("| | | | |n");
- for (x; x <= x_end + pow(10, -15); x = x + dx)//шаг.
- {
- double MC = MyCos(x, eps) * MyCos(x, eps);
- double XD = x * cos(3 * x) * x * cos(3 * x);
- d = sqrt(fabs(MC - XD));
- //d = sqrt(fabs(MyCos(x, eps) - x * cos(3 * x)));///////////////////////////////////////////////////
- printf("| %10.6f | %15.10f | %15.10f | %f |n", x, MyCos(x, eps), x*cos(3 * x), d);
- }
- printf("|______________|___________________|____________________|______________|n");
- break;
- }
- }
- cout << "Введите x_ideal" << endl;
- cin >> x_ideal;
- printf(" _____________ ___________________ ____________________ ______________ n");
- printf("|______eps____|___MyFunction(x)___|_____x*cos(3*x)_____|_______d______|n");
- printf("| | | | |n");
- for (int i = 1; i <= 7; i++)
- {
- double e = pow(0.1, i);
- double MC = MyCos(x_ideal, e) * MyCos(x_ideal, e);
- double XD = x_ideal * cos(3 * x_ideal) * x_ideal * cos(3 * x_ideal);
- //d = sqrt(fabs(MyCos(x_ideal, e) - x_ideal * cos(3 * x_ideal)));
- //while (fabsl(MyCos - (x_ideal * cos(3 * x_ideal))) >= eps);
- d = sqrt(fabs(MC - XD));
- printf("| %9.7f | %15.10f | %15.10f | %f |n", e, MyCos(x_ideal, e), x_ideal*cos(3 * x_ideal), d);
- }
- printf("|_____________|___________________|____________________|______________|n");
- system("pause");
- return 0;
- }
- int OneP(int q)
- {
- int a = -1;
- for (int w = 0; w < q; w++)
- {
- a = (-1) * a;
- }
- return a;
- }
- double fact(int n)
- {
- if (n == 0)
- {
- return 1;
- }
- if (n > 0)
- {
- return n * fact(n - 1);
- }
- }
- double MyCos(double x, double eps)
- {
- double sum = 0, a;
- for (int k = 0; fabs(OneP(k + 1) * pow(3, 2 * k) * pow(x, 2 * k + 1) / fact(2 * k) + OneP(k) * pow(3, 2 * k + 2) * pow(x, 2 * k + 3) / fact(2 * k + 2)) > eps; k++)
- {
- a = OneP(k + 1) * pow(3, 2 * k) * pow(x, 2 * k + 1) / fact(2 * k);
- sum = sum + a;
- }
- return sum;
- }`
- sum = 0
- item = x
- i = 1
- do {
- item = - item * x * x * 3.0 * 3.0 / (2 * i * (2 * i - 1))
- sum += item
- i++
- } while (fabs(item) >= eps);
Add Comment
Please, Sign In to add comment