public void EllipticFParameterOverUnityTest() { var e = Elliptic.FDouble(1.01); var f = e(1); Assert.IsTrue(Math.Abs(f - 1.23037473300409532633) < 1e-12); }
public void EllipticFTest() { var z = new[] { new Complex(-0.670791254938757, -0.0938159212065481), new Complex(0.528053930350357, -1.07956370130938), new Complex(-0.557287707188084, -1.00272777341254), new Complex(0.320745728918526, 0.287620039090474), new Complex(-0.420904792797892, 0.642254696882941), new Complex(0.109863468987495, -0.47809418429494), new Complex(-0.272688296113657, 0.197822903078282), new Complex(10.9863468987495, -0.47809418429494), new Complex(-27.2688296113657, 0.197822903078282), }; var expected = new[] { new Complex(-0.68620842267039771730, -0.10047616775855015460), new Complex(0.42868733998557565682, -1.05995343584072013101), new Complex(-0.46942504702869457356, -1.00008738595868835155), new Complex(0.31819382130927205251, 0.29124965412479359813), new Complex(-0.39580478305810881056, 0.64709397408138872245), new Complex(0.10569294199103250250, -0.47295612599211204389), new Complex(-0.27204914758137346116, 0.19984298803088524405), new Complex(12.12391310952531579389, -0.5977215792388405620), new Complex(-30.1535374477487750443, 0.22663693321479046126), }; for (int i = 0; i < expected.Length; i++) { Complex f; f = Elliptic.F(z[i], 0.333); var err = (f - expected[i]).Magnitude; Assert.IsTrue(err < 1e-14); } }
public void EllipticFParameterPoint9Test() { var e = Elliptic.FDouble(0.9); var f = e(.5); Assert.IsTrue(Math.Abs(f - 0.51976394243782869496) < 1e-12); }
public void EllipticFNegativeParameterTest() { var e = Elliptic.FDouble(-4.3); var f = e(2.718); Assert.IsTrue(Math.Abs(f - 1.6006675004822180492) < 1e-12); }
public void EllipticNomeTest() { double q, x; q = Elliptic.Nome(0); Assert.AreEqual(0, q); q = Elliptic.Nome(1); Assert.AreEqual(1, q); q = Elliptic.Nome(0.2); x = 0.01394285727531827; Assert.IsTrue(Math.Abs(x - q) < 1e-10); q = Elliptic.Nome(0.4); x = 0.03188334731336318; Assert.IsTrue(Math.Abs(x - q) < 1e-10); q = Elliptic.Nome(0.6); x = 0.05702025781460968; Assert.IsTrue(Math.Abs(x - q) < 1e-10); q = Elliptic.Nome(0.8); x = 0.09927369733882490; Assert.IsTrue(Math.Abs(x - q) < 1e-10); }
public void EllipticFLargeArgumentTest() { var x = 1436.699529559065124036301546242965863291805609504612854879; var f = Elliptic.F(1000, .8); Assert.IsTrue(Math.Abs(x - f) < 1e-12); f = Elliptic.FDouble(.8)(1000); Assert.IsTrue(Math.Abs(x - f) < 1e-12); }
public void Evaluate() { Elliptic function = new Elliptic(); Vector v1 = new Vector(new double[] { 0, 0 }); Vector v2 = new Vector(new double[] { 1, 2 }); Assert.AreEqual(0, function.Evaluate(v1)); Assert.AreEqual(4000001, function.Evaluate(v2)); }
public void EllipticFModulusOneHalfTest() { double f; var e = Elliptic.FDouble(Math.Sqrt(0.5)); f = Elliptic.F(.5, Math.Sqrt(0.5)); Assert.IsTrue(Math.Abs(f - 0.51516665702885808770) < 1e-12); f = e(0); Assert.AreEqual(0, f); f = e(1); Assert.IsTrue(Math.Abs(f - 1.1310061601574670032) < 1e-12); }
public void EllipticFMatchesComplexTest() { var rand = new Random("EllipticFMatchesComplexTest".GetHashCode()); for (int i = 0; i < 100; i++) { var m = rand.NextDouble(); var efm = Elliptic.FComplex(m); var z = RandomZ(rand); var f1 = Elliptic.F(z, m); var f2 = efm(z); Assert.AreEqual(f1, f2); } }
public void EllipticFMatchesDoubleTest() { var rand = new Random("EllipticFMatchesDoubleTest".GetHashCode()); for (int i = 0; i < 100; i++) { var m = rand.NextDouble(); var efm = Elliptic.FDouble(m); var x = Math.Sqrt(-2 * Math.Log(rand.NextDouble())) * Math.Cos(Math.PI * rand.NextDouble()); var f1 = Elliptic.F(x, m); var f2 = efm(x); Assert.AreEqual(f1, f2); } }
public override void GetAnalogPrototype(Coefficient[] coefs) // public void GetAnalogPrototype2(Coefficient[] coefs) { double m1 = this.m1; double m1p = 1 - this.m1; double Kk1 = Elliptic.K(m1); double Kk1p = Elliptic.K(m1p); double m = Elliptic.InverseQ(Math.Exp(-Math.PI * Kk1p / (this.order * Kk1))); double mp = 1 - m; double Kk = Elliptic.K(m); double phi, sn_p, cn_p, dn_p; double v = Elliptic.F(Math.Atan(1 / this.epsilon), m1p) * Kk / (this.order * Kk1); Elliptic.Jacobi(v, mp, out phi, out sn_p, out cn_p, out dn_p); for (int i = this.order - 1, j = 0; i > 0; i -= 2, ++j) { Coefficient coef = coefs[j]; double sn, cn, dn; double u = Kk * (double)i / this.order; Elliptic.Jacobi(u, m, out phi, out sn, out cn, out dn); double denom = 1 - dn * dn * sn_p * sn_p; double re = -cn * dn * sn_p * cn_p / denom; double im = -sn * dn_p / denom; double alpha = -2 * re; double beta = re * re + im * im; double gamma = 1 / (m * sn * sn); coef.a[0] = 1; coef.a[1] = alpha / beta; coef.a[2] = 1 / beta; coef.b[0] = 1; coef.b[1] = 0; coef.b[2] = 1 / gamma; } if ((this.order & 1) == 1) { Coefficient coef = coefs[this.order / 2]; double denom = 1 - sn_p * sn_p; double re = -sn_p * cn_p / denom; coef.a[0] = 1; coef.a[1] = -1 / re; coef.a[2] = 0; coef.b[0] = 1; coef.b[1] = 0; coef.b[2] = 0; } }
public static void elliptic_inc_pim_values_test() //****************************************************************************80 // // Purpose: // // ELLIPTIC_INC_PIM_VALUES_TEST tests ELLIPTIC_INC_PIM_VALUES. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 24 June 2018 // // Author: // // John Burkardt // { double m = 0; double n = 0; double phi = 0; double pim = 0; Console.WriteLine(""); Console.WriteLine("ELLIPTIC_INC_PIM_VALUES_TEST:"); Console.WriteLine(" ELLIPTIC_INC_PIM_VALUES stores values of"); Console.WriteLine(" the incomplete elliptic integral of the third"); Console.WriteLine(" kind, with parameters PHI, N and M."); Console.WriteLine(""); Console.WriteLine(" PHI N M Pi(PHI,N,M)"); Console.WriteLine(""); int n_data = 0; while (true) { Elliptic.elliptic_inc_pim_values(ref n_data, ref phi, ref n, ref m, ref pim); if (n_data == 0) { break; } Console.WriteLine(" " + phi.ToString("0.########").PadLeft(12) + " " + n.ToString("0.########").PadLeft(12) + " " + m.ToString("0.########").PadLeft(12) + " " + pim.ToString("0.################").PadLeft(24) + ""); } }
/// <summary> /// フィルタの零点/極を計算。 /// </summary> /// <param name="roots">零点/極一覧の格納先</param> public override void GetZeroPole(ZeroPole[] roots) { double m1 = this.m1; double m1p = 1 - this.m1; double Kk1 = Elliptic.K(m1); double Kk1p = Elliptic.K(m1p); double temp1 = -Math.PI * Kk1p / (this.order * Kk1); double temp2 = Math.Exp(temp1); double m = Elliptic.InverseQ(Math.Exp(-Math.PI * Kk1p / (this.order * Kk1))); double mp = 1 - m; double k = Math.Sqrt(m); double Kk = Elliptic.K(m); double Kkp = Elliptic.K(mp); double temp3 = (Kk / Kkp) / (Kk1 / Kk1p); double phi, sn_p, cn_p, dn_p; double v = Elliptic.F(Math.Atan(1 / this.epsilon), m1p) * Kk / (this.order * Kk1); Elliptic.Jacobi(v, mp, out phi, out sn_p, out cn_p, out dn_p); for (int i = this.order - 1, j = 0; i > 0; i -= 2, ++j) { double sn, cn, dn; double u = Kk * (double)i / this.order; Elliptic.Jacobi(u, m, out phi, out sn, out cn, out dn); double denom = 1 - dn * dn * sn_p * sn_p; double re = -cn * dn * sn_p * cn_p / denom; double im = -sn * dn_p / denom; roots[j].zero = new Root(Root.Type.Complex, 0, 1 / (k * sn)); roots[j].pole = new Root(Root.Type.Complex, re, im); } if ((this.order & 1) == 1) { double denom = 1 - sn_p * sn_p; double re = -sn_p * cn_p / denom; roots[this.order / 2].zero = new Root(Root.Type.None, 0, 0); roots[this.order / 2].pole = new Root(Root.Type.Single, re, 0); } }
public static void elliptic_pik_values_test() //****************************************************************************80 // // Purpose: // // ELLIPTIC_PIK_VALUES_TEST tests ELLIPTIC_PIK_VALUES. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 31 May 2018 // // Author: // // John Burkardt // { double k = 0; double n = 0; double pik = 0; Console.WriteLine(""); Console.WriteLine("ELLIPTIC_PIK_VALUES_TEST:"); Console.WriteLine(" ELLIPTIC_PIK_VALUES stores values of"); Console.WriteLine(" the complete elliptic integral of the third"); Console.WriteLine(" kind, with parameter K."); Console.WriteLine(""); Console.WriteLine(" N K Pi(N,K)"); Console.WriteLine(""); int n_data = 0; for (;;) { Elliptic.elliptic_pik_values(ref n_data, ref n, ref k, ref pik); if (n_data == 0) { break; } Console.WriteLine(" " + n.ToString("0.########").PadLeft(12) + " " + k.ToString("0.########").PadLeft(12) + " " + pik.ToString("0.################").PadLeft(24) + ""); } }
public static void elliptic_inc_fk_values_test() //****************************************************************************80 // // Purpose: // // ELLIPTIC_INC_FK_VALUES_TEST tests ELLIPTIC_INC_FK_VALUES. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 24 June 2018 // // Author: // // John Burkardt // { double fk = 0; double k = 0; double phi = 0; Console.WriteLine(""); Console.WriteLine("ELLIPTIC_INC_FK_VALUES_TEST:"); Console.WriteLine(" ELLIPTIC_INC_FK_VALUES stores values of"); Console.WriteLine(" the incomplete elliptic integral of the first"); Console.WriteLine(" kind, with parameters PHI, K."); Console.WriteLine(""); Console.WriteLine(" PHI K F(PHI,K)"); Console.WriteLine(""); int n_data = 0; while (true) { Elliptic.elliptic_inc_fk_values(ref n_data, ref phi, ref k, ref fk); if (n_data == 0) { break; } Console.WriteLine(" " + phi.ToString("0.########").PadLeft(12) + " " + k.ToString("0.########").PadLeft(12) + " " + fk.ToString("0.################").PadLeft(24) + ""); } }
public void EllipticNomeWithKPrimeTest() { double q, x, K, KPrime; q = Elliptic.Nome(0, out K, out KPrime); Assert.AreEqual(0, q); Assert.IsTrue(Math.Abs(K - Math.PI / 2) < 1e-10); Assert.IsTrue(double.IsPositiveInfinity(KPrime)); q = Elliptic.Nome(1, out K, out KPrime); Assert.AreEqual(1, q); Assert.IsTrue(double.IsPositiveInfinity(K)); Assert.IsTrue(Math.Abs(KPrime - Math.PI / 2) < 1e-10); q = Elliptic.Nome(0.2, out K, out KPrime); x = 0.01394285727531827; Assert.IsTrue(Math.Abs(x - q) < 1e-10); x = 1.659623598610528000851247659235781517398160552079174827295; Assert.IsTrue(Math.Abs(x - K) < 1e-10); x = 2.257205326820853655083256004523387397235419281739999493155; Assert.IsTrue(Math.Abs(x - KPrime) < 1e-10); q = Elliptic.Nome(0.4, out K, out KPrime); x = 0.03188334731336318; Assert.IsTrue(Math.Abs(x - q) < 1e-10); x = 1.777519371491253323502990072871915020298234739809831817591; Assert.IsTrue(Math.Abs(x - K) < 1e-10); x = 1.949567749806025882661770790728878407362558400119072023980; Assert.IsTrue(Math.Abs(x - KPrime) < 1e-10); q = Elliptic.Nome(0.6, out K, out KPrime); x = 0.05702025781460968; Assert.IsTrue(Math.Abs(x - q) < 1e-10); x = 1.949567749806025882661770790728878407362558400119072023980; Assert.IsTrue(Math.Abs(x - K) < 1e-10); x = 1.777519371491253323502990072871915020298234739809831817591; Assert.IsTrue(Math.Abs(x - KPrime) < 1e-10); q = Elliptic.Nome(0.8, out K, out KPrime); x = 0.09927369733882490; Assert.IsTrue(Math.Abs(x - q) < 1e-10); x = 2.257205326820853655083256004523387397235419281739999493155; Assert.IsTrue(Math.Abs(x - K) < 1e-10); x = 1.659623598610528000851247659235781517398160552079174827295; Assert.IsTrue(Math.Abs(x - KPrime) < 1e-10); }
public static void elliptic_em_values_test() //****************************************************************************80 // // Purpose: // // ELLIPTIC_EM_VALUES_TEST tests ELLIPTIC_EM_VALUES. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 09 February 2007 // // Author: // // John Burkardt // { double fx = 0; double x = 0; Console.WriteLine(""); Console.WriteLine("ELLIPTIC_EM_VALUES_TEST:"); Console.WriteLine(" ELLIPTIC_EM_VALUES stores values of"); Console.WriteLine(" the complete elliptic integral of the second"); Console.WriteLine(" kind, with parameter modulus M."); Console.WriteLine(""); Console.WriteLine(" M E(M)"); Console.WriteLine(""); int n_data = 0; for (;;) { Elliptic.elliptic_em_values(ref n_data, ref x, ref fx); if (n_data == 0) { break; } Console.WriteLine(" " + x.ToString("0.########").PadLeft(12) + " " + fx.ToString("0.################").PadLeft(24) + ""); } }