Search in sources :

Example 1 with Complex

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

the class NRoots method roots.

public static IAST roots(final IExpr arg1, IAST variables, EvalEngine engine) {
    if (variables.size() != 2) {
        // factor only possible for univariate polynomials
        engine.printMessage("NRoots: factorization only possible for univariate polynomials");
        return F.NIL;
    }
    IExpr expr = evalExpandAll(arg1);
    ISymbol sym = (ISymbol) variables.arg1();
    double[] coefficients = Expr2Object.toPolynomial(expr, sym);
    if (coefficients != null) {
        LaguerreSolver solver = new LaguerreSolver(Config.DEFAULT_ROOTS_CHOP_DELTA);
        Complex[] roots = solver.solveAllComplex(coefficients, 0);
        return Object2Expr.convertComplex(roots);
    }
    IExpr denom = F.C1;
    if (expr.isAST()) {
        expr = Algebra.together((IAST) expr);
        // split expr into numerator and denominator
        denom = engine.evaluate(F.Denominator(expr));
        if (!denom.isOne()) {
            // search roots for the numerator expression
            expr = engine.evaluate(F.Numerator(expr));
        }
    }
    return rootsOfVariable(expr, denom);
}
Also used : ISymbol(org.matheclipse.core.interfaces.ISymbol) LaguerreSolver(org.hipparchus.analysis.solvers.LaguerreSolver) IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST) Complex(org.hipparchus.complex.Complex)

Example 2 with Complex

use of org.hipparchus.complex.Complex in project Orekit by CS-SI.

the class GHmsjTest method getdGHda.

/**
 * Compute directly dG/dα and dH/dα from equation 2.7.1-(14).
 * @param k x-component of the eccentricity vector
 * @param h y-component of the eccentricity vector
 * @param a 1st direction cosine
 * @param b 2nd direction cosine
 * @param m order
 * @param s d'Alembert characteristic
 * @param j index
 * @return dG/dα and dH/dα values
 */
private static double[] getdGHda(final double k, final double h, final double a, final double b, final int m, final int s, final int j) {
    final Complex kh = new Complex(k, h * sgn(s - j)).pow(FastMath.abs(s - j));
    Complex ab;
    if (FastMath.abs(s) < m) {
        ab = new Complex(a, b).pow(m - s - 1).multiply(m - s);
    } else {
        ab = new Complex(a, -b * sgn(s - m)).pow(FastMath.abs(s - m) - 1).multiply(FastMath.abs(s - m));
    }
    final Complex khab = kh.multiply(ab);
    return new double[] { khab.getReal(), khab.getImaginary() };
}
Also used : Complex(org.hipparchus.complex.Complex)

Example 3 with Complex

use of org.hipparchus.complex.Complex in project Orekit by CS-SI.

the class GHmsjTest method getGHmsj.

/**
 * Compute directly G<sup>j</sup><sub>ms</sub> and H<sup>j</sup><sub>ms</sub> from equation 2.7.1-(14).
 * @param k x-component of the eccentricity vector
 * @param h y-component of the eccentricity vector
 * @param a 1st direction cosine
 * @param b 2nd direction cosine
 * @param m order
 * @param s d'Alembert characteristic
 * @param j index
 * @return G<sub>ms</sub><sup>j</sup> and H<sup>j</sup><sub>ms</sub> values
 */
private static double[] getGHmsj(final double k, final double h, final double a, final double b, final int m, final int s, final int j) {
    final Complex kh = new Complex(k, h * sgn(s - j)).pow(FastMath.abs(s - j));
    Complex ab;
    if (FastMath.abs(s) < m) {
        ab = new Complex(a, b).pow(m - s);
    } else {
        ab = new Complex(a, -b * sgn(s - m)).pow(FastMath.abs(s - m));
    }
    final Complex khab = kh.multiply(ab);
    return new double[] { khab.getReal(), khab.getImaginary() };
}
Also used : Complex(org.hipparchus.complex.Complex)

Example 4 with Complex

use of org.hipparchus.complex.Complex in project Orekit by CS-SI.

the class GHmsjTest method getdGHdb.

/**
 * Compute directly dG/dβ and dH/dβ from equation 2.7.1-(14).
 * @param k x-component of the eccentricity vector
 * @param h y-component of the eccentricity vector
 * @param a 1st direction cosine
 * @param b 2nd direction cosine
 * @param m order
 * @param s d'Alembert characteristic
 * @param j index
 * @return dG/dβ and dH/dβ values
 */
private static double[] getdGHdb(final double k, final double h, final double a, final double b, final int m, final int s, final int j) {
    final Complex kh = new Complex(k, h * sgn(s - j)).pow(FastMath.abs(s - j));
    Complex ab;
    if (FastMath.abs(s) < m) {
        Complex ab1 = new Complex(a, b).pow(m - s - 1);
        Complex ab2 = new Complex(0., m - s);
        ab = ab1.multiply(ab2);
    } else {
        Complex ab1 = new Complex(a, -b * sgn(s - m)).pow(FastMath.abs(s - m) - 1);
        Complex ab2 = new Complex(0., FastMath.abs(s - m) * sgn(m - s));
        ab = ab1.multiply(ab2);
    }
    final Complex khab = kh.multiply(ab);
    return new double[] { khab.getReal(), khab.getImaginary() };
}
Also used : Complex(org.hipparchus.complex.Complex)

Example 5 with Complex

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

the class ComplexNum method valueOf.

public static ComplexNum valueOf(final Complex c) {
    double real = c.getReal();
    double imaginary = c.getImaginary();
    if (real == 0.0d || real == -0.0d) {
        if (imaginary == 0.0d || imaginary == -0.0d) {
            return ZERO;
        }
        return newInstance(new Complex(0.0d, imaginary));
    }
    if (imaginary == 0.0d || imaginary == -0.0d) {
        return newInstance(new Complex(real, 0.0d));
    }
    return newInstance(c);
}
Also used : IComplex(org.matheclipse.core.interfaces.IComplex) 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