use of edu.jas.root.InvalidBoundaryException 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;
}
Aggregations