Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. double f(double x, double y) {
  6.     return x+x*y+y+1;
  7. }
  8.  
  9. void prosty(double x, double y, double h, int k) {
  10.     cout << "Prosty Euler" << endl << endl;
  11.     for (int i = 1; i <= k; i++) {
  12.         y = y + h*f(x, y);
  13.         x = x + h;
  14.         cout << "x" << i << ": " << x << endl << "y" << i << ": " << y << endl;
  15.     }
  16. }
  17.  
  18. void ulepszony(double x, double y, double h, int k) {
  19.     cout << "Ulepszony Euler" << endl << endl;
  20.     for (int i = 1; i <= k; i++) {
  21.         y = y + h/2*(f(x, y) + f(x+h, y+h*f(x,y)));
  22.         x = x + h;
  23.         cout << "x" << i << ": " << x << endl << "y" << i << ": " << y << endl;
  24.     }
  25. }
  26.  
  27.  
  28.  
  29. int main() {
  30.     double h = 0.25;
  31.     double x = -1;
  32.     double y = 1;
  33.     int k = (0 - x)/h;
  34.  
  35.     cout << "Liczba krokow: " << k << endl << endl;
  36.  
  37.     prosty(x, y, h, k);
  38.     cout << endl << "------------------" << endl << endl;
  39.     ulepszony(x, y, h, k);
  40.  
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement