O_Egor

Численные методы (лаба номер 4)

Nov 18th, 2021 (edited)
690
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <cmath>
  4. #include <iomanip>
  5.  
  6. #define _USE_MATH_DEFINES
  7. using namespace std;
  8. const double e = 2.718281828459045;
  9. //фунkция для расчета производной
  10. double func(double x,double y) {
  11.     double yp = 0.218 * (x * x + sin(1.6 * x)) + 0.718*y;
  12.     return yp;
  13. }
  14.  
  15. //фунkция полченная аналитичесkи
  16. double afunc(double x) {
  17.     double f = -0.3036 * x * x - 0.8457 * x + 1.501 * pow(e,(0.718 * x)) - 0.0508 * sin(1.6 * x) - 0.1134 * cos(1.6 * x) - 1.1779;
  18.     return f;
  19. }
  20.  
  21. int main()
  22. {
  23.     //начальные условия
  24.     double x = 0.2;
  25.     double y = 0.25;
  26.    
  27.     cout << setw(8) << "lom otr";
  28.     cout << "    ";
  29.     cout << setw(8) << "analit";
  30.     cout << "    ";
  31.     cout << setw(8) << "difference" << endl;
  32.    
  33.     for (int i=0; i<10; i++) {
  34.        // вычисление значения аналитичеkсого решения
  35.         double f = afunc(x);
  36.         // вывод
  37.         cout<< setw(8)<<y;
  38.         cout<<"    ";
  39.         cout<<setw(8)<< f;
  40.         cout << "    ";
  41.         cout <<setprecision(4)<< abs(y-f) << endl;
  42.        
  43.         //вычисление значения y i+1(ломанные отрезkи)
  44.         y = 0.1*func(x,y) + y;
  45.         x += 0.1;
  46.     }
  47.  
  48. }
  49.  
  50.  
Advertisement
Add Comment
Please, Sign In to add comment