CPP 78
Zasłony Guest on 4th January 2019 01:13:42 PM
  1. // zasłony.cpp : This file contains the 'main' function. Program execution begins and ends there.
  2. //
  3.  
  4. #include "pch.h"
  5. #include <iostream>
  6. #include <cmath>
  7. using namespace std;
  8.  
  9. double f(double x)
  10. {
  11.         return pow(x, 4.0) / 500.0 - pow(x, 2.0) / 200.0 - 3.0 / 250.0;
  12. }
  13.  
  14. double g(double x)
  15. {
  16.         return -pow(x, 3.0) / 30.0 + x / 20.0 + 1.0 / 6.0;
  17. }
  18.  
  19. double polef(double a, double b, double epsilon)
  20. {
  21.         int w2 = 2;
  22.         double d = abs(b - a);
  23.         double p1 = d * f(b);
  24.         double p2 = d / 2 * f(a + d / 2) + d / 2 * f(b);
  25.         while (abs(p1 - p2) > epsilon)
  26.         {
  27.                 p1 = p2;
  28.                 p2 = 0;
  29.                 w2 = w2 * 2;
  30.                 for (int i = 1; i <= w2; i++)
  31.                 {
  32.                         p2 = p2 + (d / w2) * f(a + i * (d / w2));
  33.                 }
  34.         }
  35.         return p2;
  36. }
  37. double poleg(double a, double b, double epsilon)
  38. {
  39.         int w2 = 2;
  40.         double d = abs(b - a);
  41.         double p1 = d * abs(g(b));
  42.         double p2 = d / 2 * abs(g(a + d / 2)) + d / 2 * abs(g(b));
  43.         while (abs(p1 - p2) > epsilon)
  44.         {
  45.                 p1 = p2;
  46.                 p2 = 0;
  47.                 w2 = w2 * 2;
  48.                 for (int i = 1; i <= w2; i++)
  49.                 {
  50.                         p2 = p2 + (d / w2) * abs(g(a + i * (d / w2)));
  51.                 }
  52.         }
  53.         return p2;
  54. }
  55.  
  56. int main()
  57. {
  58.         cout << f(10) << endl;
  59.         double y1 = 19.0 + 61.0 / 125.0;
  60.         double y2 = -32.0 - 2.0 / 3.0;
  61.         double x1 = 2.0;
  62.         double epsilon = 0.001;
  63.  
  64.         double p1 = polef(2.0, 10.0, epsilon);
  65.         double p2 = poleg(2.0, 10.0, epsilon);
  66.        
  67.         cout << p1 + p2 << endl;
  68.         return 0;
  69. }

Paste is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.