1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.math.ode;
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 class TestProblem3
38 extends TestProblemAbstract {
39
40
41 double e;
42
43
44 private double[] y;
45
46
47
48
49
50 public TestProblem3(double e) {
51 super();
52 this.e = e;
53 double[] y0 = { 1 - e, 0, 0, Math.sqrt((1+e)/(1-e)) };
54 setInitialConditions(0.0, y0);
55 setFinalConditions(20.0);
56 double[] errorScale = { 1.0, 1.0, 1.0, 1.0 };
57 setErrorScale(errorScale);
58 y = new double[y0.length];
59 }
60
61
62
63
64 public TestProblem3() {
65 this(0.1);
66 }
67
68
69
70
71
72 public TestProblem3(TestProblem3 problem) {
73 super(problem);
74 e = problem.e;
75 y = (double[]) problem.y.clone();
76 }
77
78
79
80
81
82 public Object clone() {
83 return new TestProblem3(this);
84 }
85
86 public void doComputeDerivatives(double t, double[] y, double[] yDot) {
87
88
89 double r2 = y[0] * y[0] + y[1] * y[1];
90 double invR3 = 1 / (r2 * Math.sqrt(r2));
91
92
93 yDot[0] = y[2];
94 yDot[1] = y[3];
95 yDot[2] = -invR3 * y[0];
96 yDot[3] = -invR3 * y[1];
97
98 }
99
100 public double[] computeTheoreticalState(double t) {
101
102
103 double E = t;
104 double d = 0;
105 double corr = 0;
106 do {
107 double f2 = e * Math.sin(E);
108 double f0 = d - f2;
109 double f1 = 1 - e * Math.cos(E);
110 double f12 = f1 + f1;
111 corr = f0 * f12 / (f1 * f12 - f0 * f2);
112 d -= corr;
113 E = t + d;
114 } while (Math.abs(corr) > 1.0e-12);
115
116 double cosE = Math.cos(E);
117 double sinE = Math.sin(E);
118
119 y[0] = cosE - e;
120 y[1] = Math.sqrt(1 - e * e) * sinE;
121 y[2] = -sinE / (1 - e * cosE);
122 y[3] = Math.sqrt(1 - e * e) * cosE / (1 - e * cosE);
123
124 return y;
125 }
126
127 }