киса

 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
public class Rk1 {
private static ArrayList<Point> y;
private static int begin, end;
private static int n;
public static void start(int a, int b, int numSteps, Сoefficients coeff) {
begin = a;
end = b;
n = numSteps;
double h = 1.0*(end - begin)/n;
double D0 = coeff.getA() + h;
double D1 = h;
y = new ArrayList<Point>(n+1);
for(int i = 0; i <= n; i++) {
y.add(new Point());
}
y.get(0).x = coeff.getA();
y.get(0).y = 0;
y.get(1).x = D0;
y.get(1).y = D1;
for(int i = 2; i <= n; i++) {
y.get(i).x = (h*h*coeff.f(x(i-1)) - (1-h*coeff.p(x(i-1))/2)*y.get(i-2).x - (h*h*coeff.q(x(i-1))-2)*y.get(i-1).x )/(1+h*coeff.p(x(i-1))/2);
y.get(i).y = (- (1-h*coeff.p(x(i-1))/2)*y.get(i-2).y - (h*h*coeff.q(x(i-1))-2)*y.get(i-1).y )/(1+h*coeff.p(x(i-1))/2);
}
double c = (coeff.getB() - y.get(n).x)/y.get(n).y;
for(int i = 0; i <= n; i++) {
System.out.println(
Double.toString(x(i)) + "\t" + Double.toString(y.get(i).x+c*y.get(i).y)
);
}
}
private static double x(int i) { return 1.0*i*(end - begin)/n; }
}