1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.hipparchus.special.elliptic.carlson;
18
19 import org.hipparchus.util.FastMath;
20 import org.hipparchus.util.MathArrays;
21
22
23
24
25 class RjRealDuplication extends RealDuplication {
26
27
28 private double delta;
29
30
31 private double sM;
32
33
34
35
36
37
38
39
40 RjRealDuplication(final double x, final double y, final double z, final double p, final double delta) {
41 super(x, y, z, p);
42 this.delta = delta;
43 }
44
45
46 @Override
47 protected void initialMeanPoint(final double[] va) {
48 va[4] = (va[0] + va[1] + va[2] + va[3] * 2) / 5.0;
49 }
50
51
52 @Override
53 protected double convergenceCriterion(final double r, final double max) {
54 return max / (FastMath.sqrt(FastMath.sqrt(FastMath.sqrt(r * 0.25))));
55 }
56
57
58 @Override
59 protected void update(final int m, final double[] vaM, final double[] sqrtM, final double fourM) {
60 final double dM = (sqrtM[3] + sqrtM[0]) * (sqrtM[3] + sqrtM[1]) * (sqrtM[3] + sqrtM[2]);
61 if (m == 0) {
62 sM = dM * 0.5;
63 } else {
64
65 final double rM = sM * (FastMath.sqrt(delta / (sM * sM * fourM) + 1.0) + 1.0);
66 sM = (dM * rM - delta / (fourM * fourM)) / ((dM + rM / fourM) * 2);
67 }
68
69
70 final double lambdaA = sqrtM[0] * sqrtM[1];
71 final double lambdaB = sqrtM[0] * sqrtM[2];
72 final double lambdaC = sqrtM[1] * sqrtM[2];
73
74
75 vaM[0] = MathArrays.linearCombination(0.25, vaM[0], 0.25, lambdaA, 0.25, lambdaB, 0.25, lambdaC);
76 vaM[1] = MathArrays.linearCombination(0.25, vaM[1], 0.25, lambdaA, 0.25, lambdaB, 0.25, lambdaC);
77 vaM[2] = MathArrays.linearCombination(0.25, vaM[2], 0.25, lambdaA, 0.25, lambdaB, 0.25, lambdaC);
78 vaM[3] = MathArrays.linearCombination(0.25, vaM[3], 0.25, lambdaA, 0.25, lambdaB, 0.25, lambdaC);
79 vaM[4] = MathArrays.linearCombination(0.25, vaM[4], 0.25, lambdaA, 0.25, lambdaB, 0.25, lambdaC);
80
81 }
82
83
84 @Override
85 protected double evaluate(final double[] va0, final double aM, final double fourM) {
86
87
88 final double inv = 1.0 / (aM * fourM);
89 final double bigX = (va0[4] - va0[0]) * inv;
90 final double bigY = (va0[4] - va0[1]) * inv;
91 final double bigZ = (va0[4] - va0[2]) * inv;
92 final double bigP = (bigX + bigY + bigZ) * -0.5;
93 final double bigP2 = bigP * bigP;
94
95
96 final double xyz = bigX * bigY * bigZ;
97 final double e2 = bigX * (bigY + bigZ) + bigY * bigZ - bigP * bigP * 3;
98 final double e3 = xyz + bigP * 2 * (e2 + bigP2 * 2);
99 final double e4 = (xyz * 2 + bigP * (e2 + bigP2 * 3)) * bigP;
100 final double e5 = xyz * bigP2;
101
102 final double e2e2 = e2 * e2;
103 final double e2e3 = e2 * e3;
104 final double e2e4 = e2 * e4;
105 final double e2e5 = e2 * e5;
106 final double e3e3 = e3 * e3;
107 final double e3e4 = e3 * e4;
108 final double e2e2e2 = e2e2 * e2;
109 final double e2e2e3 = e2e2 * e3;
110
111
112
113 final double poly = ((e3e4 + e2e5) * RdRealDuplication.E3_E4_P_E2_E5 +
114 e2e2e3 * RdRealDuplication.E2_E2_E3 +
115 e2e4 * RdRealDuplication.E2_E4 +
116 e3e3 * RdRealDuplication.E3_E3 +
117 e2e2e2 * RdRealDuplication.E2_E2_E2 +
118 e5 * RdRealDuplication.E5 +
119 e2e3 * RdRealDuplication.E2_E3 +
120 e4 * RdRealDuplication.E4 +
121 e2e2 * RdRealDuplication.E2_E2 +
122 e3 * RdRealDuplication.E3 +
123 e2 * RdRealDuplication.E2 +
124 RdRealDuplication.CONSTANT) /
125 RdRealDuplication.DENOMINATOR;
126 final double polyTerm = poly / (aM * FastMath.sqrt(aM) * fourM);
127
128
129 final double rcTerm = new RcRealDuplication(1.0, delta / (sM * sM * fourM) + 1.0).integral() * 3 / sM;
130
131 return polyTerm + rcTerm;
132
133 }
134
135 }