Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _USE_MATH_DEFINES
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <string>
- #include <sstream>
- #include <iomanip>
- #include <cmath>
- #include <math.h>
- using namespace std;
- int count_r = 9;
- double eps = 0.001;
- double a = 0;//1kek
- double b = 0.9;//2
- double f(double x) {
- //return x*x*log(x);
- //return 1/(x*x-1);
- return x*asin(x);
- }
- double f1(double x) {
- return asin(x) + x/sqrt(1-x*x);
- }
- double f2(double x) {
- //return (6 * x*x + 2) / (pow(x*x - 1, 3));
- return -(x*x - 2.0) / pow((1 - x*x), 1.5);
- }
- int main() {
- system("color F2");
- ifstream fin("in.txt");
- ofstream fout("res.txt");
- double x2 = b;
- double M = abs(f2(x2));
- {
- cout << "M = " << M << endl;
- double h1 = sqrt(eps * 12 / M / abs(b - a));
- double h2 = sqrt(eps * 12 / M / abs(b - a));
- double res1 = 0, res2 = 0;
- {
- cout << "h1 < " << h1 << endl;
- double n = (b - a) / h1;
- cout << "n1 ~= " << n << endl;
- while ((int)n % 4 != 0) {
- n += 1;
- }
- n = (int(n));
- cout << "n1 = " << n << endl;
- //n = 32;
- h1 = (b - a) / n;
- cout << "h1 = " << h1 << endl;
- //cout << "~ = " << (f(a) + f(b))*h / 2 << endl;
- for (int i = 1; i < n; i++) {
- res1 += f(a + h1 * i);
- }
- res1 += f(a) / 2 + f(b) / 2;
- res1 *= h1;
- }
- cout << "------------------------------------" << endl;
- {
- h2 = 2 * h1;
- cout << "h < " << h2 << endl;
- double n = (b - a) / h2;
- cout << "n2 ~= " << n << endl;
- /*while ((int)n % 4 != 0) {
- n += 1;
- }*/
- n = (int(n));
- cout << "n2 = " << n << endl;
- //n = 32;
- h2 = (b - a) / n;
- cout << "h2 = " << h2 << endl;
- //cout << "~ = " << (f(a) + f(b))*h / 2 << endl;
- for (int i = 1; i < n; i++) {
- res2 += f(a + h2 * i);
- }
- res2 += f(a) / 2 + f(b) / 2;
- res2 *= h2;
- }
- cout << "------------------------------------" << endl;
- cout << "res1 = " << res1 << " " << "res2 = " << res2 << endl;
- cout << "delta = " << (res2 - res1) / 3 << '\n';
- }
- {
- double h1 = sqrt(eps * 12 / M / abs(b - a));
- double h2 = sqrt(eps * 12 / M / abs(b - a));
- double res1 = 0, res2 = 0;
- cout << "------------------------------------" << endl;
- {
- cout << "h1 < " << h1 << endl;
- double n = (b - a) / h1;
- cout << "n1 ~= " << n << endl;
- while ((int)n % 4 != 0) {
- n += 1;
- }
- n = (int(n));
- cout << "n1 = " << n << endl;
- //n = 32;
- h1 = (b - a) / n;
- cout << "h1 = " << h1 << endl;
- //cout << "~ = " << (f(a) + f(b))*h / 2 << endl;
- //int m = n / 2;
- for (int i = 1; i < n; i++) {
- if (i%2 == 0) res1 += f(a + h1 * i);
- else res1 += 2*f(a + h1 * i);
- }
- res1 += f(a) / 2 + f(b) / 2;
- res1 *= 2*h1/3;
- }
- cout << "------------------------------------" << endl;
- {
- h2 = 2 * h1;
- cout << "h < " << h2 << endl;
- double n = (b - a) / h2;
- cout << "n2 ~= " << n << endl;
- /*while ((int)n % 4 != 0) {
- n += 1;
- }*/
- n = (int(n));
- cout << "n2 = " << n << endl;
- //n = 32;
- h2 = (b - a) / n;
- cout << "h2 = " << h2 << endl;
- //cout << "~ = " << (f(a) + f(b))*h / 2 << endl;
- for (int i = 1; i < n; i++) {
- if (i % 2 == 0) res2 += f(a + h2 * i);
- else res2 += 2 * f(a + h2 * i);
- }
- res2 += f(a) / 2 + f(b) / 2;
- res2 *= 2 * h2 / 3;
- }
- cout << "------------------------------------" << endl;
- cout << "res1 = " << res1 << " " << "res2 = " << res2 << endl;
- cout << "delta = " << (res2 - res1) / 3 << '\n';
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement