Created by Roman on 10 04 14 public class Lab_8 private static final d

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
* Created by Roman on 10.04.14.
*/
public class Lab_8 {
private static final double A = 0.01;
private static final double FROM = 0;
private static final double TO = 3;
private static final double H = 0.1;
private static final double Y_20 = 0.5;
private static double function(double a, double x, double y1, double y2) {
return y2 * x * (-a) - y1;
}
public static void main(String... args) {
int iteration = (int) ((TO - FROM) / H + 1);
double[] x = new double[iteration];
x[0] = FROM;
double[] y1 = new double[iteration];
y1[0] = 0;
double[] y2 = new double[iteration];
y2[0] = Y_20;
for (int index = 1; index < iteration; index++) {
double y_11 = H * y2[index - 1];
double y_21 = H * function(A, x[index - 1], y1[index - 1], y2[index - 1]);
double y_12 = H * y2[index - 1] + y_21 / 2.0;
double y_22 = H * function(A, x[index - 1] + H / 2.0, y1[index - 1] + y_11 / 2.0, y2[index - 1] + y_21 / 2.0);
double y_13 = H * y2[index - 1] + y_22 / 2.0;
double y_23 = H * function(A, x[index - 1] + H / 2.0, y1[index - 1] + y_12 / 2.0, y2[index - 1] + y_22 / 2.0);
double y_14 = H * y2[index - 1] + y_23;
double y_24 = H * function(A, x[index - 1] + H, y1[index - 1] + y_13, y2[index - 1] + y_23);
y2[index] = y2[index - 1] + (y_21 + 2 * y_22 + 2 * y_23 + y_24) / 6.0;
y1[index] = y1[index - 1] + (y_11 + 2 * y_12 + 2 * y_13 + y_14) / 6.0;
x[index] = x[index - 1] + H;
}
System.out.print("output...");
}
}