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