Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <math.h>
  4. #include <fstream>
  5.  
  6. using namespace std;
  7.  
  8. #define AMOUNT 1000
  9.  
  10. double f(double y) {
  11. return (0.9 * y - 0.1 * pow(y, 2));
  12. }
  13.  
  14. int main() {
  15. double a = 0.9, b = 0.1, h = 0.01;
  16. double Y[AMOUNT];
  17. Y[0] = 1;
  18. Y[1] = Y[0] + h * f(Y[0]);
  19. Y[2] = Y[1] + h * f(Y[1]);
  20. Y[3] = Y[2] + h * f(Y[2]);
  21.  
  22. cout << "y_" << "0" << ": " << Y[0] << endl;
  23.  
  24. for (size_t k = 2; k<AMOUNT; k++) {
  25. Y[k+1] = (1.33333 * Y[k] - 0.333333 * Y[k - 1]) + 0.666666 * h * f(Y[k + 1]);
  26. if (AMOUNT == 1000) {
  27. if (k % 2 != 0) {
  28. cout << "y_" << k << ": " << Y[k] << endl;
  29. }
  30. } else { cout << "y_" << k << ": " << Y[k] << endl; }
  31. }
  32.  
  33.  
  34. //proverka
  35. cout << "y_" << "0" << ": " << Y[0] << endl;
  36. cout << "y_" << "1" << ": " << Y[1] << endl;
  37. cout << "y_" << "2" << ": " << Y[2] << endl;
  38. cout << "y_" << "3" << ": " << Y[3] << endl;
  39. system("pause");
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement