1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.hipparchus.special.elliptic.jacobi;
18
19 import org.hipparchus.complex.Complex;
20 import org.hipparchus.special.elliptic.legendre.LegendreEllipticIntegral;
21 import org.hipparchus.util.FastMath;
22 import org.hipparchus.util.MathUtils;
23 import org.junit.Assert;
24 import org.junit.Test;
25
26 public class JacobiThetaTest {
27
28 @Test
29 public void testNoConvergence() {
30 Assert.assertTrue(new JacobiTheta(Double.NaN).values(Complex.ZERO).theta1().isNaN());
31 }
32
33 @Test
34 public void testRealZero() {
35 final double k = 0.675;
36 final double m = k * k;
37 final double q = LegendreEllipticIntegral.nome(m);
38 final double t3Ref = 1 + 2 * (q + FastMath.pow(q, 4) + FastMath.pow(q, 9) + FastMath.pow(q, 16));
39 final double theta3 = new JacobiTheta(q).values(Complex.ZERO).theta3().getRealPart();
40 Assert.assertEquals(t3Ref, theta3, 1.0e-12);
41 }
42
43 @Test
44 public void testWolframAlpha() {
45 final Theta theta = new JacobiTheta(0.25).values(new Complex(2, 1));
46 Assert.assertEquals( 2.21896723745108057500, theta.theta1().getRealPart(), 1.0e-15);
47 Assert.assertEquals(-1.56332891301806559779, theta.theta1().getImaginaryPart(), 1.0e-15);
48 Assert.assertEquals(-0.07520617984531674751, theta.theta2().getRealPart(), 1.0e-15);
49 Assert.assertEquals(-1.24993491278546664559, theta.theta2().getImaginaryPart(), 1.0e-15);
50 Assert.assertEquals(-0.25931139474579522847, theta.theta3().getRealPart(), 1.0e-15);
51 Assert.assertEquals( 1.16230083178353441578, theta.theta3().getImaginaryPart(), 1.0e-15);
52 Assert.assertEquals( 2.19722649038852886551, theta.theta4().getRealPart(), 1.0e-15);
53 Assert.assertEquals(-1.58416769196278632848, theta.theta4().getImaginaryPart(), 1.0e-15);
54 }
55
56 @Test
57 public void testQuarterPeriod() {
58 final double k = 0.675;
59 final double m = k * k;
60 final double q = LegendreEllipticIntegral.nome(m);
61 final double theta3 = new JacobiTheta(q).values(Complex.ZERO).theta3().getRealPart();
62 Assert.assertEquals(LegendreEllipticIntegral.bigK(m), MathUtils.SEMI_PI * theta3 * theta3, 1.0e-12);
63 }
64
65 @Test
66 public void testEllipticFunctions() {
67
68 final double z = 1.3;
69 final double k = 0.675;
70 final double m = k * k;
71 final double q = LegendreEllipticIntegral.nome(m);
72 final double bigK = LegendreEllipticIntegral.bigK(m);
73 final double zeta = MathUtils.SEMI_PI * z / bigK;
74 final JacobiTheta jt = new JacobiTheta(q);
75 final Theta theta0 = jt.values(Complex.ZERO);
76 final Theta thetaZ = jt.values(new Complex(zeta));
77
78
79
80 final JacobiElliptic je = JacobiEllipticBuilder.build(m);
81 final CopolarN valuesN = je.valuesN(z);
82 final CopolarD valuesD = je.valuesD(z);
83 final CopolarC valuesC = je.valuesC(z);
84 final double t02 = theta0.theta2().getRealPart();
85 final double t03 = theta0.theta3().getRealPart();
86 final double t04 = theta0.theta4().getRealPart();
87 final double tz1 = thetaZ.theta1().getRealPart();
88 final double tz2 = thetaZ.theta2().getRealPart();
89 final double tz3 = thetaZ.theta3().getRealPart();
90 final double tz4 = thetaZ.theta4().getRealPart();
91 Assert.assertEquals(valuesN.sn(), t03 * tz1 / (t02 * tz4), 1.0e-15);
92 Assert.assertEquals(valuesN.cn(), t04 * tz2 / (t02 * tz4), 1.0e-15);
93 Assert.assertEquals(valuesN.dn(), t04 * tz3 / (t03 * tz4), 1.0e-15);
94 Assert.assertEquals(valuesD.sd(), t03 * t03 * tz1 / (t02 * t04 * tz3), 1.0e-15);
95 Assert.assertEquals(valuesD.cd(), t03 * tz2 / (t02 * tz3), 1.0e-15);
96 Assert.assertEquals(valuesC.sc(), t03 * tz1 / (t04 * tz2), 1.0e-15);
97
98 }
99
100 }