Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <math.h>
- #include <iomanip>
- #include <cstdlib>
- #include <cmath>
- #define LC_CTYPE
- #define _USE_MATH_DEFINES
- #include<cmath>
- # define M_PI 3.14159265358979323846
- using namespace std;
- double pi = 3.14159265358979323846;
- double myf(int n, double x) {
- int a = (2 * n) - 1;
- return (((a - 2) * (a - 2)) - (x * x)) / ((a * a) - (x * x));
- }
- double f(double x, double e) {
- double z1 = 1 / (1 - x * x);
- double z2 = 0;
- int n = 2;
- double k = myf(n, x);
- double res = z1;
- while (abs(z2 - z1 * k) >= e)
- {
- z2 = z1 * k;
- res += z1 * k;
- z1 = z2;
- n++;
- k = myf(n, x);
- }
- if (abs(res) > 1e10) {
- return INFINITY;
- }
- return ((4 * x) / (pi)) * res;
- }
- /*}
- else {
- return INFINITY;
- }
- }
- }
- else {
- while (abs(z2 - z1 * k) >= e)
- {
- z2 = z1 * k;
- res += z1 * k;
- z1 = z2;
- n++;
- k = myf(n, x);
- }
- return ((4 * x) / (M_PI)) - res;
- }
- }*/
- double F(double x) {
- double abs_x = abs(x);
- int abs_int_x = int(abs_x + 1e-10);
- if (abs(abs_x - abs_int_x) < 1e-10) {
- if (abs(abs_int_x % 2) == 0) {
- return (tan((pi * x) / 2));
- }
- else {
- return INFINITY;
- }
- }
- else {
- return (tan((pi * x) / 2));
- }
- }
- int main() {
- setlocale(LC_ALL, "rus");
- double inf = numeric_limits<double>::infinity();
- double x_start, x_end, dx, x_ideal;
- double e;
- cout << "Введите начальное значение x:" << endl;
- cin >> x_start;
- while (!cin) {
- cin.clear();
- cout << "Введите корректное значение:" << endl;
- cin >> x_start;
- }
- cout << "Введите конечное значение x:" << endl;
- cin >> x_end;
- while (!cin || x_end == x_start) {
- cin.clear();
- cout << "Введите корректное значение:" << endl;
- cin >> x_end;
- }
- cout << "Введите шаг:" << endl;
- cin >> dx;
- while (!cin || ((dx < 0) & (x_start < x_end)) || ((dx > 0) & (x_start > x_end)) || (abs(x_start - x_end) < abs(dx)) || dx == 0) {
- cin.clear();
- cout << "Введите корректное значение:" << endl;
- cin >> dx;
- }
- cout << "Введите точность:" << endl;
- cin >> e;
- while (!cin || e <= 0) {
- cin.clear();
- cout << "Введите корректное значение:" << endl;
- cin >> e;
- }
- cout << "f(x) = f(x-1)*(((a-2)*(a-2))-(x*x))/((a*a)-(x*x))), где a=2n-1" << "\n";
- cout << "F(x) = tg((pi*x)/2) " << "\n";
- cout << " _________________________________________________________________________________________________" << endl;
- cout << "|" << setw(12.5) << "x" << setw(12.5) << "|" << setw(13.5) << "f(x)" << setw(11.5) << "|" << setw(14) << "F(x)" << setw(11) << "|" << setw(15) << "delta" << setw(10) << "|" << endl;
- cout << " _________________________________________________________________________________________________" << endl;
- for (double i = x_start; i <= x_end + 0.000001; i += dx) {
- double f1 = f(i, e);
- double F1 = F(i);
- double del;
- if ((f1 == inf && F1 == inf) || f1 == -inf && F1 == inf) {
- del = INFINITY;
- }
- else {
- del = sqrt(abs(f1 * f1 - F1 * F1));
- }
- cout << fixed << setprecision(6);
- cout << "|" << setw(12.5) << i << setw(12.5) << "|" << setw(13.5) << f1 << setw(11.5) << "|" << setw(14) << F1 << setw(11) << "|" << setw(15) << del << setw(10) << "|" << endl;
- cout << " _________________________________________________________________________________________________" << endl;
- }
- cout << "Введите значение x_ideal:" << endl;
- cin >> x_ideal;
- while (!cin) {
- cin.clear();
- scanf_s("%*[^\n]");
- cout << "Введите корректное значение:" << endl;
- cin >> x_ideal;
- }
- cout << " _________________________________________________________________________________________________" << endl;
- cout << "|" << setw(12.5) << "eps" << setw(12.5) << "|" << setw(13.5) << "f(x_ideal)" << setw(11.5) << "|" << setw(14) << "F(x_ideal)" << setw(11) << "|" << setw(15) << "delta" << setw(10) << "|" << endl;
- cout << " _________________________________________________________________________________________________" << endl;
- for (double i = 0.1; i >= 0.0000001; i = i / 10) {
- double f1 = f(x_ideal, i);
- double F1 = F(x_ideal);
- double del;
- if (f1 == inf && F1 == inf) {
- del = INFINITY;
- }
- else {
- del = sqrt(abs(f1 * f1 - F1 * F1));
- }
- cout << fixed << setprecision(6);
- cout << "|" << setw(12.5) << i << setw(12.5) << "|" << setw(13.5) << f1 << setw(11.5) << "|" << setw(14) << F1 << setw(11) << "|" << setw(15) << del << setw(10) << "|" << endl;
- cout << " _________________________________________________________________________________________________" << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment