Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.75 KB | None | 0 0
  1. #include<iostream>
  2. #include<cmath>
  3.  
  4. using namespace std;
  5.  
  6. double FunctionX(double t, double x, double y) {
  7.     return -1 / t*x + y;
  8. }
  9.  
  10. double FunctionY(double t, double x, double y) {
  11.     return -(2 * x) / (t*t) + y / t;
  12. }
  13.  
  14. int main()
  15. {
  16.     int l, n = 2000;
  17.     double t0 = 1, t3 = 3;
  18.     double K1_1[2], K1_2[2], K2_1[2], K2_2[2];
  19.     double x = 1, y = 1, h = fabs((t3 - t0) / n), temporary, T0 = t0;
  20.  
  21.  
  22.     for (int w = 1; w <= n; w++)
  23.     {
  24.  
  25.         for (int i = 0; i < 2; i++)
  26.         {
  27.             switch (i) {
  28.             case 0: temporary = h * FunctionX(T0, x, y);
  29.                 break;
  30.             case 1: temporary = h *FunctionY(T0, x, y);
  31.                 break;
  32.             }
  33.             K1_1[i] = temporary;
  34.         }
  35.  
  36.         for (int i = 0; i < 2; i++)
  37.         {
  38.             switch (i) {
  39.             case 0: temporary = h*FunctionX(T0 + 0.5*h, x + 0.5*K1_1[0], y + 0.5*K1_1[1]);
  40.                 break;
  41.             case 1: temporary = h*FunctionY(T0 + 0.5*h, x + 0.5*K1_1[0], y + 0.5*K1_1[1]);
  42.                 break;
  43.             }
  44.             K1_2[i] = temporary;
  45.         }
  46.  
  47.         for (int i = 0; i < 2; i++)
  48.         {
  49.             switch (i) {
  50.             case 0: temporary = h*FunctionX(T0 + 0.5*h, x + 0.5*K1_2[0], y + 0.5*K1_2[1]);
  51.                 break;
  52.             case 1: temporary = h*FunctionY(T0 + 0.5*h, x + 0.5*K1_2[0], y + 0.5*K1_2[1]);
  53.                 break;
  54.             }
  55.             K2_1[i] = temporary;
  56.         }
  57.  
  58.         for (int i = 0; i < 2; i++)
  59.         {
  60.             switch (i) {
  61.             case 0: temporary = h*FunctionX(T0 + h, x + K2_1[0], y + K2_1[1]);
  62.                 break;
  63.             case 1: temporary = h*FunctionY(T0 + h, x + K2_1[0], y + K2_1[1]);
  64.                 break;
  65.             }
  66.             K2_2[i] = temporary;
  67.         }
  68.  
  69.         x = x + (K1_1[0] + 2 * K1_2[0] + 2 * K2_1[0] + K2_2[0]) / 6;
  70.         y = y + (K1_1[1] + 2 * K1_2[1] + 2 * K2_1[1] + K2_2[1]) / 6;
  71.         T0 = t0 + w*h;
  72.         l = w;
  73.  
  74.     }
  75.    
  76.    
  77.     cout << "Ilosc iteracji : " << l << endl;
  78.     cout << " x(3) = " << x << endl;
  79.     cout << " y(3) = " << y << endl;
  80.  
  81.  
  82.  
  83.     system("pause");
  84.     return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement