use of org.hipparchus.complex.Complex in project symja_android_library by axkr.
the class EllipticFunctionsJS method weierstrassP.
public static Complex weierstrassP(Complex x, Complex g2, Complex g3) {
// if ( !isComplex(x) ) x = complex(x);
Complex[] sol = weierstrassRoots(g2, g3);
Complex e1 = sol[0];
Complex e2 = sol[1];
Complex e3 = sol[2];
// Whittaker & Watson, Section 22.351
Complex m = e2.subtract(e3).divide(e1.subtract(e3));
Complex pow = jacobiSN(x.multiply(e1.subtract(e3).sqrt()), m).reciprocal();
pow = pow.multiply(pow);
return e3.add(e1.subtract(e3).multiply(pow));
}
use of org.hipparchus.complex.Complex in project symja_android_library by axkr.
the class JavaComplexFormFactory method convertAST.
@Override
public void convertAST(final StringBuilder buf, final IAST function) {
if (function.isNumericFunction(true)) {
try {
Complex value = EvalEngine.get().evalComplex(function);
if (value != null) {
buf.append("Complex.valueOf(");
buf.append(value.getReal());
buf.append(",");
buf.append(value.getImaginary());
buf.append(")");
return;
}
} catch (RuntimeException rex) {
//
}
}
IExpr head = function.head();
if (head.isSymbol() && function.size() > 1) {
String str = functionHead((ISymbol) head);
if (str != null) {
if (function.isPower()) {
IExpr base = function.base();
IExpr exponent = function.exponent();
if (exponent.isNumEqualRational(F.C1D2)) {
buf.append("(");
convertInternal(buf, base);
buf.append(").sqrt()");
return;
} else if (exponent.isNumEqualRational(F.CN1D2)) {
buf.append("(");
convertInternal(buf, base);
buf.append(").reciprocal().sqrt()");
return;
} else if (exponent.isMinusOne()) {
buf.append("(");
convertInternal(buf, base);
buf.append(").reciprocal()");
return;
}
}
// Complex atan2(Complex x) {
buf.append("(");
convertInternal(buf, function.first());
buf.append(")" + str);
if (function.isAST(S.ArcTan, 3)) {
buf.append("2");
}
convertArgs(buf, head, function, 2);
return;
}
}
if (function.headID() > 0) {
if (function.isAST(S.Defer, 2) || function.isAST(S.Evaluate, 2) || function.isAST(S.Hold, 2) || function.isUnevaluated()) {
convertInternal(buf, function.first());
return;
}
if (function.isPower()) {
IExpr base = function.base();
IExpr exponent = function.exponent();
if (exponent.isMinusOne()) {
buf.append("1.0/(");
convertInternal(buf, base);
buf.append(")");
return;
}
if (exponent.isNumEqualRational(F.C1D2)) {
buf.append("Math.sqrt(");
convertInternal(buf, base);
buf.append(")");
return;
}
if (exponent.isNumEqualRational(F.C1D3)) {
buf.append("Math.cbrt(");
convertInternal(buf, base);
buf.append(")");
return;
}
buf.append("Math.pow");
convertArgs(buf, head, function, 1);
return;
}
buf.append("F.");
buf.append(head.toString());
buf.append(".ofN(");
convertArgs(buf, head, function, 1);
buf.append(")");
return;
}
if (function.isInfinity()) {
buf.append("Double.POSITIVE_INFINITY");
return;
}
if (function.isNegativeInfinity()) {
buf.append("Double.NEGATIVE_INFINITY");
return;
}
convertInternal(buf, head);
convertArgs(buf, head, function, 1);
}
use of org.hipparchus.complex.Complex in project symja_android_library by axkr.
the class NumericArrayExpr method arrayComplexDoubleRecursive.
private static boolean arrayComplexDoubleRecursive(IAST nestedListsOfValues, int level, double[] doubleArr, int[] index) throws RangeException, TypeException {
level--;
for (int i = 1; i < nestedListsOfValues.size(); i++) {
IExpr arg = nestedListsOfValues.get(i);
if (level == 0) {
if (arg.isList()) {
return false;
}
Complex value = arg.evalComplex();
doubleArr[index[0]++] = value.getReal();
doubleArr[index[0]++] = value.getImaginary();
} else {
if (!arg.isList() || !arrayDoubleRecursive((IAST) arg, level, doubleArr, index)) {
return false;
}
}
}
return true;
}
use of org.hipparchus.complex.Complex in project symja_android_library by axkr.
the class ExprEvaluatorTest method testEvalComplex.
public void testEvalComplex() {
EvalEngine engine = new EvalEngine(true);
ExprEvaluator eval = new ExprEvaluator(engine, true, (short) 20);
String str = "1/(Pi + I)";
Complex c = eval.evalComplex(str);
assertEquals("(0.2890254822222363, -0.09199966835037525)", c.toString());
}
use of org.hipparchus.complex.Complex in project symja_android_library by axkr.
the class InverseFourier method fourier.
/**
* Uses decimation-in-time or Cooley-Tukey FFT
*
* @param vector of length of power of 2
* @param b is +1 for forward, and -1 for inverse transform
* @return discrete Fourier transform of given vector
*/
private static IAST fourier(IAST vector, int b) {
final int n = vector.argSize();
Complex[] array = Convert.list2Complex(vector);
if (array == null) {
return F.NIL;
}
// FastFourierTransformer fft = new FastFourierTransformer(DftNormalization.UNITARY);
// org.hipparchus.complex.Complex[] result = fft.transform(array, TransformType.INVERSE);
// return Object2Expr.convertComplex(true, result);
int j = 0;
for (int i = 0; i < n; ++i) {
if (j > i) {
Complex val = array[i];
array[i] = array[j];
array[j] = val;
}
int m = n >> 1;
while (m > 0 && j >= m) {
j -= m;
m >>= 1;
}
j += m;
}
int mmax = 1;
while (n > mmax) {
int istep = mmax << 1;
final double thalf = b * Math.PI / istep;
final double wtemp = Math.sin(thalf);
Complex wp = new Complex(-2 * wtemp * wtemp, Math.sin(thalf + thalf));
Complex w = Complex.ONE;
for (int m = 0; m < mmax; ++m) {
for (int i = m; i < n; i += istep) {
j = i + mmax;
Complex temp = array[j].multiply(w);
array[j] = array[i].subtract(temp);
array[i] = array[i].add(temp);
}
w = w.add(w.multiply(wp));
}
mmax = istep;
}
return F.Divide(Convert.toVector(array), F.Sqrt(n));
}
Aggregations