Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include <iomanip>
- #include <math.h>
- using namespace std;
- double func(double x) {
- return sqrt(x) - pow(cos(x), 2);
- }
- double Gaus(double a, double b, int n) {
- double h = (b - a) / n;
- double x0 = a + h / 2.;
- double x1 = x0 - (h / 2.)*0.7745966692;
- double x2 = x0 + (h / 2.)*0.7745966692;
- long double ans = 0;
- for (int i = 0; i < n; i++) {
- ans += (5 * func(x1) + 8 * func(x0) + 5 * func(x2));
- x0 += h;
- x1 = x0 - (h / 2.)*0.7745966692;
- x2 = x0 + (h / 2.)*0.7745966692;
- }
- return ans*h/18.;
- }
- int main(void)
- {
- setlocale(LC_ALL, "Russian");
- cout << "a=";
- double a;
- cin >> a;
- cout << "b=";
- double b;
- cin >> b;
- int m = 3;
- double x[20];
- double y[20];
- double h = (b - a) / 10.;
- int k = (b - a) / h;
- for (int i = 0; i <= k + 1; i++)
- {
- x[i] = a + i * h;
- y[i] = func(x[i]);
- }
- double dy[20];
- dy[0] = (4 * y[1] - y[2] - 3 * y[0]) / (2 * h);
- dy[k] = (4 * y[k - 1] - y[k - 2] - 3 * y[k]) / (2 * h);
- for (int i = 1; i < k; i++) dy[i] = (y[i + 1] - y[i - 1]) / (2 * h);
- double Dy[20];
- for (int i = 0; i <= k; i++)Dy[i] = 2 * x[i] - 5 * sin(x[i]);
- double d2y[20];
- d2y[0] = (y[0] - 2 * y[1] + y[2]) / pow(h, 2);
- d2y[k] = (y[k-2] - 2 * y[k-1] + y[k]) / pow(h, 2);
- for (int i = 1; i < k; i++)d2y[i] = (y[i - 1] - 2 * y[i] + y[i + 1]);
- double D2y[20];
- for (int i = 0; i <= k; i++)D2y[i] = 2 - 5 * cos(x[i]);
- cout << setw(5) << "X" << setw(10) << "Y" << setw(10) << "dY" << setw(10) << "DY" << setw(10) << "d2Y" << setw(10) << "D2Y" << endl;
- for(int i = 0;i<=k;i++)
- cout << setw(5) << x[i] << setw(10) << y[i] << setw(10) << dy[i] << setw(10) << Dy[i] << setw(10) << d2y[i] << setw(10) << D2y[i] << endl;
- cout << Gaus(a, b, m);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement