fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int main() {
  6.  
  7. double y1, y2, y3, y4, Eq;
  8. double h = 0.5, x0 = 1;
  9. int L = 10;
  10.  
  11. vector<double> x = {x0};
  12. vector<double> y = {2};
  13.  
  14. auto f = [](double x, double y){return x/y-y/x;};
  15.  
  16. for (int i=0;i<L;i++){
  17. x.push_back(x[i]+h);
  18.  
  19. y1 = f(x[i],y[i]);
  20. y2 = f(x[i]+0.5*h,y[i]+0.5*h*y1);
  21. y3 = f(x[i]+0.5*h,y[i]+0.5*h*y2);
  22. y4 = f(x[i]+h,y[i]+h*y3);
  23. Eq = y[i] + (1.00/6.00) *h* (y1 + 2*y2 + 2*y3 + y4);
  24. y.push_back(Eq);
  25. }
  26.  
  27. for (double i : x)
  28. {cout << i << " ";}
  29.  
  30. cout << "\n";
  31.  
  32. for (double j : y)
  33. {cout << j << " ";}
  34.  
  35.  
  36. return 0;
  37. }
  38.  
Success #stdin #stdout 0s 544KB
stdin
Standard input is empty
stdout
1  1.5  2  2.5  3  3.5  4  4.5  5  5.5  6  
2  1.63965  1.69767  1.921  2.21196  2.53251  2.86723  3.2093  3.55548  3.90409  4.2542