Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cmath>
- using namespace std;
- double FunctionX(double t, double x, double y) {
- return -1 / t*x + y;
- }
- double FunctionY(double t, double x, double y) {
- return -(2 * x) / (t*t) + y / t;
- }
- int main()
- {
- int l, n = 2000;
- double t0 = 1, t3 = 3;
- double K1_1[2], K1_2[2], K2_1[2], K2_2[2];
- double x = 1, y = 1, h = fabs((t3 - t0) / n), temporary, T0 = t0;
- for (int w = 1; w <= n; w++)
- {
- for (int i = 0; i < 2; i++)
- {
- switch (i) {
- case 0: temporary = h * FunctionX(T0, x, y);
- break;
- case 1: temporary = h *FunctionY(T0, x, y);
- break;
- }
- K1_1[i] = temporary;
- }
- for (int i = 0; i < 2; i++)
- {
- switch (i) {
- case 0: temporary = h*FunctionX(T0 + 0.5*h, x + 0.5*K1_1[0], y + 0.5*K1_1[1]);
- break;
- case 1: temporary = h*FunctionY(T0 + 0.5*h, x + 0.5*K1_1[0], y + 0.5*K1_1[1]);
- break;
- }
- K1_2[i] = temporary;
- }
- for (int i = 0; i < 2; i++)
- {
- switch (i) {
- case 0: temporary = h*FunctionX(T0 + 0.5*h, x + 0.5*K1_2[0], y + 0.5*K1_2[1]);
- break;
- case 1: temporary = h*FunctionY(T0 + 0.5*h, x + 0.5*K1_2[0], y + 0.5*K1_2[1]);
- break;
- }
- K2_1[i] = temporary;
- }
- for (int i = 0; i < 2; i++)
- {
- switch (i) {
- case 0: temporary = h*FunctionX(T0 + h, x + K2_1[0], y + K2_1[1]);
- break;
- case 1: temporary = h*FunctionY(T0 + h, x + K2_1[0], y + K2_1[1]);
- break;
- }
- K2_2[i] = temporary;
- }
- x = x + (K1_1[0] + 2 * K1_2[0] + 2 * K2_1[0] + K2_2[0]) / 6;
- y = y + (K1_1[1] + 2 * K1_2[1] + 2 * K2_1[1] + K2_2[1]) / 6;
- T0 = t0 + w*h;
- l = w;
- }
- cout << "Ilosc iteracji : " << l << endl;
- cout << " x(3) = " << x << endl;
- cout << " y(3) = " << y << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement