use of org.hipparchus.complex.Complex in project symja_android_library by axkr.
the class ComplexNum method quotientRemainder.
/**
* Return the quotient and remainder as an array <code>[quotient, remainder]</code> of the
* division of <code>Complex</code> numbers <code>c1, c2</code>.
*
* <p>
* See
*
* <ul>
* <li><a href="https://en.wikipedia.org/wiki/Gaussian_integer">Wikipedia - Gaussian integer</a>
* <li><a href=
* "http://fermatslasttheorem.blogspot.com/2005/06/division-algorithm-for-gaussian.html">Division
* Algorithm for Gaussian Integers </a>
* </ul>
*
* @param c1
* @param c2
* @return the quotient and remainder as an array <code>[quotient, remainder]</code>
*/
public static Complex[] quotientRemainder(Complex c1, Complex c2) {
// use hipparchus Complex implementation - see:
// https://github.com/Hipparchus-Math/hipparchus/issues/67
Complex remainder = c1.remainder(c2);
Complex quotient = c1.subtract(remainder).divide(c2).rint();
return new Complex[] { quotient, remainder };
// double numeratorReal = c1.getReal() * c2.getReal() + //
// c1.getImaginary() * c2.getImaginary();
// double numeratorImaginary = c1.getReal() * (-c2.getImaginary()) + //
// c2.getReal() * c1.getImaginary();
// double denominator = c2.getReal() * c2.getReal() + //
// c2.getImaginary() * c2.getImaginary();
// if (denominator == 0.0) {
// throw new IllegalArgumentException("Denominator cannot be zero.");
// }
//
// double divisionReal = Math.rint(numeratorReal / denominator);
// double divisionImaginary = Math.rint(numeratorImaginary / denominator);
//
// double remainderReal = c1.getReal() - //
// (c2.getReal() * divisionReal) + //
// (c2.getImaginary() * divisionImaginary);
// double remainderImaginary = c1.getImaginary() - //
// (c2.getReal() * divisionImaginary) - //
// (c2.getImaginary() * divisionReal);
// return new Complex[] { new Complex(divisionReal, divisionImaginary),
// new Complex(remainderReal, remainderImaginary) };
}
use of org.hipparchus.complex.Complex in project symja_android_library by axkr.
the class HypergeometricJS method hypergeometricU.
public static Complex hypergeometricU(Complex a, Complex b, Complex x) {
double useAsymptotic = 20;
// asymptotic form as per Johansson arxiv.org/abs/1606.06977
if (x.norm() > useAsymptotic) {
return x.pow(a.negate()).multiply(hypergeometric2F0(a, a.add(b.negate()).add(1.0), x.reciprocal().negate()));
}
if (b.equals(Complex.ONE) || (F.isNumIntValue(b.getReal(), 1) && F.isZero(b.getImaginary()))) {
return complexAverage(arg -> hypergeometricU(a, arg, x), b);
}
Complex t1 = Arithmetic.lanczosApproxGamma(b.subtract(1)).multiply(Arithmetic.lanczosApproxGamma(a).reciprocal()).multiply(x.pow(Complex.ONE.subtract(b)).multiply(hypergeometric1F1(a.add(b.negate()).add(1.0), b.negate().add(2.0), x)));
Complex t2 = Arithmetic.lanczosApproxGamma(Complex.ONE.subtract(b)).multiply(Arithmetic.lanczosApproxGamma(a.add(b.negate()).add(1.0)).reciprocal()).multiply(hypergeometric1F1(a, b, x));
return t1.add(t2);
}
use of org.hipparchus.complex.Complex in project symja_android_library by axkr.
the class HypergeometricJS method hypergeometricSeries.
public static Complex hypergeometricSeries(Complex[] A, Complex[] B, Complex x) {
// , double
// tolerance
// see https://github.com/paulmasson/math/issues/12
Complex s = Complex.ONE;
Complex p = Complex.ONE;
int i = 0;
while (Math.abs(p.getReal()) > Config.SPECIAL_FUNCTIONS_TOLERANCE || Math.abs(p.getImaginary()) > Config.SPECIAL_FUNCTIONS_TOLERANCE) {
for (int j = 0; j < A.length; j++) {
p = p.multiply(A[j]);
A[j] = A[j].add(1.0);
}
for (int j = 0; j < B.length; j++) {
p = p.divide(B[j]);
B[j] = B[j].add(1.0);
}
p = p.multiply(x).divide(++i);
s = s.add(p);
if (i > 500) {
throw new ArgumentTypeException("maximum iteration exceeded in hypergeometricSeries (Complex)");
}
}
return s;
}
use of org.hipparchus.complex.Complex in project symja_android_library by axkr.
the class Convert method list2Complex.
public static Complex[] list2Complex(final IAST vector) throws ClassCastException {
if (vector == null) {
return null;
}
final Object header = vector.head();
if (header != S.List) {
return null;
}
final int size = vector.argSize();
final Complex[] elements = new Complex[size];
EvalEngine engine = EvalEngine.get();
for (int i = 0; i < size; i++) {
IExpr element = vector.get(i + 1);
elements[i] = engine.evalComplex(element);
}
return elements;
}
use of org.hipparchus.complex.Complex in project symja_android_library by axkr.
the class BesselJS method airyBi.
public static Complex airyBi(double x) {
if (F.isZero(x)) {
return new Complex(1.0 / Math.pow(3.0, 1.0 / 6.0) / GammaJS.gamma(2.0 / 3.0));
}
if (x < 0) {
Complex xMinus = new Complex(-x);
Complex z = xMinus.pow(1.5).multiply(2.0 / 3.0);
return xMinus.divide(3.0).sqrt().multiply(besselJ(-1.0 / 3.0, z).subtract(besselJ(1.0 / 3.0, z)));
}
Complex xc = new Complex(x);
Complex z = xc.pow(1.5).multiply(2.0 / 3.0);
return xc.divide(3.0).sqrt().multiply(besselI(1.0 / 3.0, z).add(besselI(-1.0 / 3.0, z)));
}
Aggregations