Advertisement
Dambosin

int 5

May 13th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <math.h>
  5. using namespace std;
  6.  
  7. double func(double x) {
  8. return sqrt(x) - pow(cos(x), 2);
  9. }
  10.  
  11. double Gaus(double a, double b, int n) {
  12. double h = (b - a) / n;
  13. double x0 = a + h / 2.;
  14. double x1 = x0 - (h / 2.)*0.7745966692;
  15. double x2 = x0 + (h / 2.)*0.7745966692;
  16. long double ans = 0;
  17. for (int i = 0; i < n; i++) {
  18. ans += (5 * func(x1) + 8 * func(x0) + 5 * func(x2));
  19. x0 += h;
  20. x1 = x0 - (h / 2.)*0.7745966692;
  21. x2 = x0 + (h / 2.)*0.7745966692;
  22. }
  23. return ans*h/18.;
  24. }
  25. int main(void)
  26. {
  27. setlocale(LC_ALL, "Russian");
  28. cout << "a=";
  29. double a;
  30. cin >> a;
  31. cout << "b=";
  32. double b;
  33. cin >> b;
  34. int m = 3;
  35. double x[20];
  36. double y[20];
  37. double h = (b - a) / 10.;
  38. int k = (b - a) / h;
  39. for (int i = 0; i <= k + 1; i++)
  40. {
  41. x[i] = a + i * h;
  42. y[i] = func(x[i]);
  43. }
  44. double dy[20];
  45. dy[0] = (4 * y[1] - y[2] - 3 * y[0]) / (2 * h);
  46. dy[k] = (4 * y[k - 1] - y[k - 2] - 3 * y[k]) / (2 * h);
  47. for (int i = 1; i < k; i++) dy[i] = (y[i + 1] - y[i - 1]) / (2 * h);
  48. double Dy[20];
  49. for (int i = 0; i <= k; i++)Dy[i] = 2 * x[i] - 5 * sin(x[i]);
  50. double d2y[20];
  51. d2y[0] = (y[0] - 2 * y[1] + y[2]) / pow(h, 2);
  52. d2y[k] = (y[k-2] - 2 * y[k-1] + y[k]) / pow(h, 2);
  53. for (int i = 1; i < k; i++)d2y[i] = (y[i - 1] - 2 * y[i] + y[i + 1]);
  54. double D2y[20];
  55. for (int i = 0; i <= k; i++)D2y[i] = 2 - 5 * cos(x[i]);
  56. cout << setw(5) << "X" << setw(10) << "Y" << setw(10) << "dY" << setw(10) << "DY" << setw(10) << "d2Y" << setw(10) << "D2Y" << endl;
  57. for(int i = 0;i<=k;i++)
  58. 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;
  59. cout << Gaus(a, b, m);
  60. return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement