Search in sources :

Example 1 with Rectangle

use of edu.jas.root.Rectangle in project symja_android_library by axkr.

the class RootIntervals method croots.

/**
	 * Complex numeric roots intervals.
	 * 
	 * @param ast
	 * @return
	 */
public static IAST croots(final IExpr arg, boolean numeric) {
    try {
        VariablesSet eVar = new VariablesSet(arg);
        if (!eVar.isSize(1)) {
            // only possible for univariate polynomials
            return F.NIL;
        }
        IExpr expr = F.evalExpandAll(arg);
        ASTRange r = new ASTRange(eVar.getVarList(), 1);
        List<IExpr> varList = r;
        ComplexRing<BigRational> cfac = new ComplexRing<BigRational>(new BigRational(1));
        ComplexRootsAbstract<BigRational> cr = new ComplexRootsSturm<BigRational>(cfac);
        JASConvert<Complex<BigRational>> jas = new JASConvert<Complex<BigRational>>(varList, cfac);
        GenPolynomial<Complex<BigRational>> poly = jas.numericExpr2JAS(expr);
        Squarefree<Complex<BigRational>> engine = SquarefreeFactory.<Complex<BigRational>>getImplementation(cfac);
        poly = engine.squarefreePart(poly);
        List<Rectangle<BigRational>> roots = cr.complexRoots(poly);
        BigRational len = new BigRational(1, 100000L);
        IAST resultList = F.List();
        if (numeric) {
            for (Rectangle<BigRational> root : roots) {
                Rectangle<BigRational> refine = cr.complexRootRefinement(root, poly, len);
                resultList.append(JASConvert.jas2Numeric(refine.getCenter(), Config.DEFAULT_ROOTS_CHOP_DELTA));
            }
        } else {
            IAST rectangleList;
            for (Rectangle<BigRational> root : roots) {
                rectangleList = F.List();
                Rectangle<BigRational> refine = cr.complexRootRefinement(root, poly, len);
                rectangleList.append(JASConvert.jas2Complex(refine.getNW()));
                rectangleList.append(JASConvert.jas2Complex(refine.getSW()));
                rectangleList.append(JASConvert.jas2Complex(refine.getSE()));
                rectangleList.append(JASConvert.jas2Complex(refine.getNE()));
                resultList.append(rectangleList);
            // System.out.println("refine = " + refine);
            }
        }
        return resultList;
    } catch (InvalidBoundaryException e) {
        if (Config.SHOW_STACKTRACE) {
            e.printStackTrace();
        }
    } catch (JASConversionException e) {
        if (Config.SHOW_STACKTRACE) {
            e.printStackTrace();
        }
    }
    return F.NIL;
}
Also used : ASTRange(org.matheclipse.core.expression.ASTRange) InvalidBoundaryException(edu.jas.root.InvalidBoundaryException) BigRational(edu.jas.arith.BigRational) ComplexRootsSturm(edu.jas.root.ComplexRootsSturm) Rectangle(edu.jas.root.Rectangle) VariablesSet(org.matheclipse.core.convert.VariablesSet) JASConversionException(org.matheclipse.core.eval.exception.JASConversionException) Complex(edu.jas.poly.Complex) ComplexRing(edu.jas.poly.ComplexRing) JASConvert(org.matheclipse.core.convert.JASConvert) IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST)

Aggregations

BigRational (edu.jas.arith.BigRational)1 Complex (edu.jas.poly.Complex)1 ComplexRing (edu.jas.poly.ComplexRing)1 ComplexRootsSturm (edu.jas.root.ComplexRootsSturm)1 InvalidBoundaryException (edu.jas.root.InvalidBoundaryException)1 Rectangle (edu.jas.root.Rectangle)1 JASConvert (org.matheclipse.core.convert.JASConvert)1 VariablesSet (org.matheclipse.core.convert.VariablesSet)1 JASConversionException (org.matheclipse.core.eval.exception.JASConversionException)1 ASTRange (org.matheclipse.core.expression.ASTRange)1 IAST (org.matheclipse.core.interfaces.IAST)1 IExpr (org.matheclipse.core.interfaces.IExpr)1