1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.hipparchus.ode;
24
25 import org.hipparchus.util.FastMath;
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 public class TestProblem3 extends TestProblemAbstract {
45
46
47 double e;
48
49
50
51
52
53 public TestProblem3(double e) {
54 super(0.0, new double[] { 1 - e, 0, 0, FastMath.sqrt((1+e)/(1-e)) }, 20.0,
55 new double[] { 1.0, 1.0, 1.0, 1.0 });
56 this.e = e;
57 }
58
59
60
61
62 public TestProblem3() {
63 this(0.1);
64 }
65
66 @Override
67 public double[] doComputeDerivatives(double t, double[] y) {
68
69 final double[] yDot = new double[getDimension()];
70
71
72 double r2 = y[0] * y[0] + y[1] * y[1];
73 double invR3 = 1 / (r2 * FastMath.sqrt(r2));
74
75
76 yDot[0] = y[2];
77 yDot[1] = y[3];
78 yDot[2] = -invR3 * y[0];
79 yDot[3] = -invR3 * y[1];
80
81 return yDot;
82
83 }
84
85 @Override
86 public double[] computeTheoreticalState(double t) {
87
88
89 double E = t;
90 double d = 0;
91 double corr = 999.0;
92 for (int i = 0; (i < 50) && (FastMath.abs(corr) > 1.0e-12); ++i) {
93 double f2 = e * FastMath.sin(E);
94 double f0 = d - f2;
95 double f1 = 1 - e * FastMath.cos(E);
96 double f12 = f1 + f1;
97 corr = f0 * f12 / (f1 * f12 - f0 * f2);
98 d -= corr;
99 E = t + d;
100 }
101
102 double cosE = FastMath.cos(E);
103 double sinE = FastMath.sin(E);
104
105 double[] y = new double[getDimension()];
106 y[0] = cosE - e;
107 y[1] = FastMath.sqrt(1 - e * e) * sinE;
108 y[2] = -sinE / (1 - e * cosE);
109 y[3] = FastMath.sqrt(1 - e * e) * cosE / (1 - e * cosE);
110
111 return y;
112 }
113
114 }