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.Field;
26 import org.hipparchus.CalculusFieldElement;
27 import org.hipparchus.util.MathArrays;
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 public class TestFieldProblem3<T extends CalculusFieldElement<T>>
48 extends TestFieldProblemAbstract<T> {
49
50
51 T e;
52
53
54
55
56
57 public TestFieldProblem3(T e) {
58 super(convert(e.getField(), 0.0),
59 createY0(e),
60 convert(e.getField(), 20.0),
61 convert(e.getField(), 1.0, 1.0, 1.0, 1.0));
62 this.e = e;
63 }
64
65 private static <T extends CalculusFieldElement<T>> T[] createY0(final T e) {
66 T[] y0 = MathArrays.buildArray(e.getField(), 4);
67 y0[0] = e.subtract(1).negate();
68 y0[1] = e.getField().getZero();
69 y0[2] = e.getField().getZero();
70 y0[3] = e.add(1).divide(y0[0]).sqrt();
71 return y0;
72 }
73
74
75
76
77
78 public TestFieldProblem3(Field<T> field) {
79 this(field.getZero().add(0.1));
80 }
81
82 @Override
83 public T[] doComputeDerivatives(T t, T[] y) {
84
85 final T[] yDot = MathArrays.buildArray(getField(), getDimension());
86
87
88 T r2 = y[0].multiply(y[0]).add(y[1].multiply(y[1]));
89 T invR3 = r2.multiply(r2.sqrt()).reciprocal();
90
91
92 yDot[0] = y[2];
93 yDot[1] = y[3];
94 yDot[2] = invR3.negate().multiply(y[0]);
95 yDot[3] = invR3.negate().multiply(y[1]);
96
97 return yDot;
98
99 }
100
101 @Override
102 public T[] computeTheoreticalState(T t) {
103
104 final T[] y = MathArrays.buildArray(getField(), getDimension());
105
106
107 T E = t;
108 T d = convert(t.getField(), 0);
109 T corr = convert(t.getField(), 999.0);
110 for (int i = 0; (i < 50) && (corr.norm() > 1.0e-12); ++i) {
111 T f2 = e.multiply(E.sin());
112 T f0 = d.subtract(f2);
113 T f1 = e.multiply(E.cos()).subtract(1).negate();
114 T f12 = f1.add(f1);
115 corr = f0.multiply(f12).divide(f1.multiply(f12).subtract(f0.multiply(f2)));
116 d = d.subtract(corr);
117 E = t.add(d);
118 }
119
120 T cosE = E.cos();
121 T sinE = E.sin();
122
123 y[0] = cosE.subtract(e);
124 y[1] = e.multiply(e).subtract(1).negate().sqrt().multiply(sinE);
125 y[2] = sinE.divide(e.multiply(cosE).subtract(1));
126 y[3] = e.multiply(e).subtract(1).negate().sqrt().multiply(cosE).divide(e.multiply(cosE).subtract(1).negate());
127
128 return y;
129
130 }
131
132 }