Search in sources :

Example 11 with Complex

use of org.hipparchus.complex.Complex in project symja_android_library by axkr.

the class BesselJS method besselJ.

public static Complex besselJ(Complex n, Complex x) {
    if (F.isNumIntValue(n.getReal()) && n.getReal() < 0.0 && F.isZero(n.getImaginary())) {
        return new Complex(-1.0).pow(n).multiply(besselJ(n.negate(), x));
    }
    Complex product = x.divide(2.0).pow(n).divide(Arithmetic.lanczosApproxGamma(n.add(1.0)));
    Complex sqrX = x.multiply(x);
    return product.multiply(HypergeometricJS.hypergeometric0F1(n.add(1), sqrX.multiply(-0.25)));
}
Also used : Complex(org.hipparchus.complex.Complex)

Example 12 with Complex

use of org.hipparchus.complex.Complex in project symja_android_library by axkr.

the class BesselJS method airyAi.

public static Complex airyAi(double x) {
    if (F.isZero(x)) {
        return new Complex(1.0 / Math.pow(3.0, 2.0 / 3.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.sqrt().divide(3.0).multiply(besselJ(1.0 / 3.0, z).add(besselJ(-1.0 / 3.0, z)));
    }
    Complex xc = new Complex(x);
    Complex z = xc.pow(1.5).multiply(2.0 / 3.0);
    return besselK(1.0 / 3.0, z).multiply(1 / Math.PI).multiply(xc.divide(3.0).sqrt());
}
Also used : Complex(org.hipparchus.complex.Complex)

Example 13 with Complex

use of org.hipparchus.complex.Complex in project symja_android_library by axkr.

the class BesselJS method airyBi.

public static Complex airyBi(Complex 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.getReal() < 0) {
        Complex xMinus = x.negate();
        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 z = x.pow(1.5).multiply(2.0 / 3.0);
    return x.divide(3.0).sqrt().multiply(besselI(1.0 / 3.0, z).add(besselI(-1.0 / 3.0, z)));
}
Also used : Complex(org.hipparchus.complex.Complex)

Example 14 with Complex

use of org.hipparchus.complex.Complex in project symja_android_library by axkr.

the class BesselJS method besselK.

public static Complex besselK(Complex n, Complex x) {
    final int useAsymptotic = 10;
    // for averaging over integer orders until write code for limit
    double delta = 1e-5;
    // asymptotic form as per Johansson
    if (x.norm() > useAsymptotic) {
        Complex t1 = new Complex(Math.PI / 2.0).divide(x).sqrt().multiply(x.negate().exp());
        // Complex t2 = HypergeometricJS.hypergeometricSeries(new Complex[] { n.add(0.5),
        // n.negate().add(0.5) },
        // new Complex[0], new Complex(-0.5).divide(x));
        Complex t2 = HypergeometricJS.hypergeometric2F0(n.add(0.5), new Complex(0.5).subtract(n), new Complex(-0.5).divide(x));
        return t1.multiply(t2);
    }
    EvalEngine engine = EvalEngine.get();
    int recursionLimit = engine.getRecursionLimit();
    try {
        if (recursionLimit > 0) {
            int counter = engine.incRecursionCounter();
            if (counter > recursionLimit) {
                RecursionLimitExceeded.throwIt(counter, S.BesselK);
            }
        }
        if (n.isMathematicalInteger()) {
            double nRe = n.getReal();
            // see https://github.com/Hipparchus-Math/hipparchus/issues/67
            return besselK(new Complex(nRe + delta), x).add(besselK(new Complex(nRe - delta), x)).divide(2.0);
        }
        Complex product = new Complex(Math.PI / 2.0).divide(n.multiply(Math.PI).sin());
        return product.multiply(besselI(n.negate(), x).subtract(besselI(n, x)));
    } finally {
        if (recursionLimit > 0) {
            engine.decRecursionCounter();
        }
    }
}
Also used : EvalEngine(org.matheclipse.core.eval.EvalEngine) Complex(org.hipparchus.complex.Complex)

Example 15 with Complex

use of org.hipparchus.complex.Complex in project symja_android_library by axkr.

the class BesselJS method besselY.

public static Complex besselY(Complex n, Complex x) {
    // for averaging over integer orders until write code for limit
    if (n.isMathematicalInteger()) {
        EvalEngine engine = EvalEngine.get();
        final int recursionLimit = engine.getRecursionLimit();
        try {
            if (recursionLimit > 0) {
                int counter = engine.incRecursionCounter();
                if (counter > recursionLimit) {
                    RecursionLimitExceeded.throwIt(counter, F.BesselY(F.complexNum(n), F.complexNum(x)));
                }
            }
            double delta = 1e-5;
            // TODO use differentiator here
            return besselY(new Complex(n.getReal() + delta), x).add(besselY(new Complex(n.getReal() - delta), x).divide(2.0));
        } finally {
            if (recursionLimit > 0) {
                engine.decRecursionCounter();
            }
        }
    }
    Complex sum = n.multiply(Math.PI).cos().multiply(besselJ(n, x)).subtract(besselJ(n.negate(), x));
    return sum.divide(n.multiply(Math.PI).sin());
}
Also used : EvalEngine(org.matheclipse.core.eval.EvalEngine) Complex(org.hipparchus.complex.Complex)

Aggregations

Complex (org.hipparchus.complex.Complex)74 ArgumentTypeException (org.matheclipse.core.eval.exception.ArgumentTypeException)12 EvalEngine (org.matheclipse.core.eval.EvalEngine)8 IExpr (org.matheclipse.core.interfaces.IExpr)6 Config (org.matheclipse.core.basic.Config)4 F (org.matheclipse.core.expression.F)4 IAST (org.matheclipse.core.interfaces.IAST)4 Gamma (org.hipparchus.special.Gamma)3 Arithmetic (org.matheclipse.core.builtin.Arithmetic)3 IterationLimitExceeded (org.matheclipse.core.eval.exception.IterationLimitExceeded)3 ValidateException (org.matheclipse.core.eval.exception.ValidateException)3 S (org.matheclipse.core.expression.S)3 IComplex (org.matheclipse.core.interfaces.IComplex)3 ISymbol (org.matheclipse.core.interfaces.ISymbol)3 Math.abs (java.lang.Math.abs)2 ArrayList (java.util.ArrayList)2 Function (java.util.function.Function)2 IntFunction (java.util.function.IntFunction)2 DSFactory (org.hipparchus.analysis.differentiation.DSFactory)2 FiniteDifferencesDifferentiator (org.hipparchus.analysis.differentiation.FiniteDifferencesDifferentiator)2