Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <string>
- #include <fstream>
- using namespace std;
- double Analytical(double x)
- {
- if(x==0){return 1/3;}
- else{return ((2*x*x+2*x)*sin(x)+(-1*pow(x, 4)-2*pow(x, 3)-x*x+2)*cos(x)+x*x*x*x-2)/pow(x, 3);}
- }
- double Function(double x, double t)
- {
- return pow(t+x, 2)*sin(x*t);
- }
- double Right_rect(double x, double n, double h,double a)
- {
- double sum = 0;
- for (int i = 1; i <= n; i++)
- sum += h*(Function(x, a + h * i));
- return sum;
- }
- int main()
- {
- setlocale(LC_CTYPE, "Russian");
- const double PI = 3.141592653589793;
- double a = 0, b = PI, c, d, N[3], difference[3] = {0, 0, 0};
- cout << "Введите нижнюю границу для х " << endl;
- cin >> c;
- cout << "Введите верхнюю границу для х " << endl;
- cin >> d;
- if(c<0||d>PI){cout << "Выход за область определениея"; return 0;}
- cout << "Введите количество разбиений - 3 разных значения: " << endl;
- cin >> N[0] >> N[1] >> N[2];
- fstream fin("/home/daminator/Desktop/Education/KUBSU/Programming methods/Practise/Практика летняя/output.txt");
- fin << "x \t\t" << "N="<<N[0] << "\t\t" << "N=" << N[1] << "\t\t" << "N=" << N[2] << "\t\t" << "Analytical" << '\n';
- for (int i = 0; i <= 20; i++)
- {
- double x = c + i * (d - c) / 20;
- double Analytic_Integral = Analytical(x);
- fin << to_string(x) + '\t';
- for (int j = 0; j < 3; j++)
- {
- double h = (b - a) / N[j];
- double Rectangle_Integral = Right_rect(x, N[j], h, a);
- fin << to_string(Rectangle_Integral) + '\t';
- if (abs(Analytic_Integral - Rectangle_Integral) > difference[j])
- difference[j] = abs(Analytic_Integral - Rectangle_Integral);
- }
- fin << to_string(Analytic_Integral) + '\n';
- }
- fin << "Для различных значений разбиений максимальная невязка равна: \n";
- for (int i = 0; i < 3; i++)
- fin << N[i] << ": " << difference[i] << "\n";
- fin.seekg(0);
- string getcontent;
- if (fin.is_open())
- while (getline(fin, getcontent))
- cout << getcontent << endl;
- fin.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement