use of org.hipparchus.complex.Complex in project symja_android_library by axkr.
the class EllipticFunctionsJS method jacobiAmplitude.
public static Complex jacobiAmplitude(double x, double m) {
if (m > 1) {
return jacobiAmplitude(new Complex(x), new Complex(m));
}
Complex K = EllipticIntegralsJS.ellipticK(m);
// ??? .getReal() inserted
long n = Math.round(x / 2.0 / K.getReal());
// ??? .getReal() inserted
x = x - 2 * n * K.getReal();
return Complex.valueOf(Math.asin(jacobiSN(x, m)) + (n * Math.PI));
}
use of org.hipparchus.complex.Complex in project symja_android_library by axkr.
the class EllipticFunctionsJS method weierstrassInvariants.
public static Complex[] weierstrassInvariants(Complex w1, Complex w3) {
// order half periods by complex slope
if (w3.getImaginary() / w3.getReal() < w1.getImaginary() / w1.getReal()) {
Complex temp = w1;
w1 = w3;
w3 = temp;
}
Complex ratio = w3.divide(w1);
boolean conjugate = false;
if (ratio.getImaginary() < 0) {
ratio = ratio.conjugate();
conjugate = true;
}
Complex q = Complex.I.multiply(Math.PI).multiply(ratio).exp();
// en.wikipedia.org/wiki/Weierstrass's_elliptic_functions
// modified for input of half periods
Complex a = jacobiTheta(2, Complex.ZERO, q);
Complex b = jacobiTheta(3, Complex.ZERO, q);
Complex aPow4 = a.multiply(a);
aPow4 = aPow4.multiply(aPow4);
Complex aPow8 = aPow4.multiply(aPow4);
Complex bPow4 = b.multiply(b);
bPow4 = bPow4.multiply(bPow4);
Complex bPow8 = bPow4.multiply(bPow4);
Complex g2 = w1.multiply(2).pow(-4).multiply(aPow8.add(aPow4.multiply(bPow4).negate()).add(bPow8)).multiply(4.0 / 3.0 * Math.pow(Math.PI, 4));
Complex g3 = w1.multiply(2.0).pow(-6.0).multiply(8.0 / 27.0 * Math.pow(Math.PI, 6.0)).multiply(a.pow(12).add(aPow8.multiply(bPow4).multiply(-1.5)).add(aPow4.multiply(bPow8).multiply(-1.5)).add(b.pow(12)));
if (conjugate) {
g2 = g2.conjugate();
g3 = g3.conjugate();
}
return new Complex[] { g2, g3 };
}
use of org.hipparchus.complex.Complex in project symja_android_library by axkr.
the class EllipticFunctionsJS method weierstrassRoots.
public static Complex[] weierstrassRoots(Complex g2, Complex g3) {
g2 = g2.divide(4);
g3 = g3.divide(4);
Complex e1 = cubicTrigSolution(g2, g3, 0);
Complex e2 = cubicTrigSolution(g2, g3, 1);
Complex e3 = cubicTrigSolution(g2, g3, 2);
return new Complex[] { e1, e2, e3 };
}
use of org.hipparchus.complex.Complex in project symja_android_library by axkr.
the class EllipticFunctionsJS method weierstrassHalfPeriods.
public static Complex[] weierstrassHalfPeriods(Complex g2, Complex g3) {
Complex[] sol = weierstrassRoots(g2, g3);
Complex e1 = sol[0];
Complex e2 = sol[1];
Complex e3 = sol[2];
Complex lambda = e1.subtract(e3).sqrt();
Complex m = e2.subtract(e3).divide(e1.subtract(e3));
Complex w1 = ellipticK(m).divide(lambda);
Complex w3 = Complex.I.multiply(ellipticK(Complex.ONE.subtract(m))).divide(lambda);
return new Complex[] { w1, w3 };
// Complex e1 = sol[0];
// Complex e2 = sol[1];
// Complex e3 = sol[2];
// Complex w1 = inverseWeierstrassP(e1, g2, g3);
// Complex w2 = inverseWeierstrassP(e2, g2, g3);
// Complex w3 = inverseWeierstrassP(e3, g2, g3);
//
// Complex[] w = new Complex[] { w1, w2, w3 };
// Arrays.sort(w, (a, b) -> (int) Math.signum((a.abs() - b.abs())));
// // w.sort( (a,b) => abs(a) - abs(b) );
// Complex smallest = w[0];
// Complex[] v = new Complex[] { w[1], w[2], //
// w[1].subtract(smallest), w[2].subtract(smallest) };
// // w.sort( (a,b) => abs(a) - abs(b) );
// Arrays.sort(v, (a, b) -> (int) Math.signum((a.abs() - b.abs())));
// return new Complex[] { smallest, v[0] };
}
use of org.hipparchus.complex.Complex in project symja_android_library by axkr.
the class EllipticFunctionsJS method jacobiAmplitude.
public static Complex jacobiAmplitude(Complex x, Complex m) {
if (m.getImaginary() == 0.0 && m.getReal() <= 1) {
Complex K = EllipticIntegralsJS.ellipticK(m.getReal());
// ??? getReal() inserted
long n = Math.round(x.getReal() / 2.0 / K.getReal());
x = x.subtract(2.0 * n * K.getReal());
if (m.getReal() < 0.0) {
Complex Kp = EllipticIntegralsJS.ellipticK(1 - m.getReal());
long p = Math.round(x.getImaginary() / 2.0 / Kp.getReal());
// bitwise test for odd integer
if ((p & 1) == 1) {
return jacobiSN(x, m).asin().negate().add(n * Math.PI);
}
}
return jacobiSN(x, m).asin().add(n * Math.PI);
}
return jacobiSN(x, m).asin();
// }
}
Aggregations