DarkDevourer

Рунге-Кутт

Oct 22nd, 2020 (edited)
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3.  
  4. double f(double x, double y);
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. double x0, y, h, x1, k1, k2, k3, k4, x, dy;
  11. int n1, n=0;
  12. setlocale(LC_ALL, "RUSSIAN");
  13. cout << "Введите x0 (начало промежутка): x0 = ";
  14. cin >> x0;
  15. cout << "Введите x1 (конец промежутка): x1 = ";
  16. cin >> x1;
  17. cout << "Введите y(x0) (значение функции в начале промежутка): y("<<x0<<") = ";
  18. cin >> y;
  19. cout << "Введите h (длену промежутка): h = ";
  20. cin >> h;
  21. cout << "y" << n << " = " << y<<endl;
  22. cout << "dy = 0" << endl << endl;
  23. n1 = floor((x1 - x0) / h);
  24. for (n = 0, x = x0; n < n1;x+=h)
  25. {
  26. n++;
  27. k1 = f(x, y);
  28. k2 = f(x + h / 2, y + (h * k1) / 2);
  29. k3 = f(x + h / 2, y + (h * k2) / 2);
  30. k4 = f(x + h, y + (h * k3));
  31. dy = h * (k1 + 2 * k2 + 2 * k3 + k4) / 6;
  32. y = y + dy;
  33. cout << "y" << n << " = " << y << endl;
  34. cout << "dy = "<< dy << endl << endl;
  35. }
  36. }
  37.  
  38. double f(double x, double y)
  39. {
  40. return((x - y) / (x + exp(y)));
  41. //return(pow(x, 2) - 2 * y);
  42. //return(x*exp(cos(y)));
  43. }
Add Comment
Please, Sign In to add comment