List of usage examples for org.apache.commons.math3.analysis.polynomials PolynomialFunction degree
public int degree()
From source file:jurbano.melodyshape.comparison.bspline.Laguerre.java
/** * Finds the real roots of a {@link PolynomialFunction} between 0 and 1, * including these./* ww w .j a v a2 s . c o m*/ * * @param f * the polynomial to find the roots. * @return the list of real roots. */ public ArrayList<Double> findRoots(PolynomialFunction f) { ArrayList<Double> realRoots = new ArrayList<Double>(); realRoots.add(0d); if (f.degree() > 0) { Complex[] roots = this.findAllComplexRoots(f); for (Complex root : roots) { if (Math.abs(root.getImaginary()) < this.epsilon) { double real = root.getReal(); if (real > 0 && real < 1) realRoots.add(real); } } } realRoots.add(1d); return realRoots; }
From source file:dom.rootlocus.beans.rLocusBean.java
public void calculateRootLocus() { System.out.println("Calculating root locus."); System.out.println("Calculating zeros."); PolynomialFunction numOLTF = utils.toPolynomialFunction(getsNum().split(" ")) .multiply(utils.toPolynomialFunction(getpNum().split(" "))); PolynomialFunction denOLTF = utils.toPolynomialFunction(getsDen().split(" ")) .multiply(utils.toPolynomialFunction(getpDen().split(" "))); Complex[] zeros, poles;/*w ww . j a v a 2 s . c om*/ zeros = new Complex[numOLTF.degree()]; if (numOLTF.degree() > 0) { zeros = utils.getRoots(numOLTF); } poles = new Complex[denOLTF.degree()]; if (denOLTF.degree() > 0) { System.out.println("Calculating poles"); poles = utils.getRoots(denOLTF); } double maxStep = utils.stepMax(poles); double k = 0.0; Complex[] roots = utils.getRoots(utils.getEC(numOLTF, denOLTF, k)); ArrayList<List<Complex>> series = utils.initializeSeries(roots.length); utils.addValuetoSerie(roots, series); double defaultInc = 0.5; while (!utils.fishisComputation(zeros, series, maxStep, k)) { k = k + defaultInc; roots = utils.getRoots(utils.getEC(numOLTF, denOLTF, k)); boolean validRoots = utils.newPointsValid(roots, series, maxStep); if (validRoots) { utils.addValuetoSerie(roots, series); defaultInc = 0.5; } else { //recalculate k value; k = k - defaultInc; defaultInc = defaultInc * 0.5; } System.out.println("k=" + k); } System.out.println("Values of root locus calculated."); setModel(utils.getDrawableData(series, getModel(), poles, zeros)); }