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