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)));
}
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());
}
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)));
}
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();
}
}
}
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());
}
Aggregations