public static void main(String[] args) { Polynomial vec = new Polynomial(); vec.add(10, 0); vec.add(15, 1); vec.add(65, 8); System.out.println("vec1: " + vec); System.out.println(); // Polynomial vec2 = new Polynomial(); // vec2.add(16, 2); // vec2.add(34, 5); // System.out.println("vec2: " + vec2); // System.out.println(); // // Polynomial vecTest = new Polynomial(); // vecTest.polySum(vec2); // System.out.println("vec16: " + vecTest); // System.out.println(); // // Polynomial vec3 = new Polynomial(); // vec3 = vec3.polySumBoth(vec, vec2); // System.out.println("vec3: " + vec3); // System.out.println(); // // Polynomial vec4 = new Polynomial(); // vec4 = vec4.polyMultiByConstant(vec, 5); // System.out.println("vec4: " + vec4); // System.out.println(); // // Polynomial vec5 = new Polynomial(); // vec5 = vec5.polyMultiplicate(vec, vec2); // System.out.println("vec5: " + vec5); // System.out.println(); // // Polynomial vec6 = new Polynomial(); // vec6 = vec6.polySubstract(vec, vec2); // System.out.println("vec6: " + vec6); // System.out.println(); // // Polynomial vec7 = new Polynomial(vec3); // vec7 = vec7.firstDerivative(); // System.out.println("vec7 first derivative from vec3: " + vec7); // System.out.println(); // // System.out.println("Evaluate vec1, x = 5 : " + vec.evaluate(5)); // System.out.println(); // System.out.println(); // // Polynomial vec8 = new Polynomial(); // vec8 = Polynomial.fromString("15x^2 + 18x^4 + 10 + 5x^2 + -2x^8"); // System.out.println(vec8); }
/* Close the loop. */ public TransferFunction closeLoop(double feedback) { Polynomial num_result = num.copy(); Polynomial den_result = num.add(den.multiply(feedback)); return new TransferFunction(num_result, den_result); }
// Update "shape" and "segments" from the current value of "points": void updateShape() { if (points.size() < 2) { shape = null; segments.clear(); return; } // Pad out the control point list using wraparound, // to make a closed spline: ArrayList extraPoints = new ArrayList(points); extraPoints.add(0, points.get(points.size() - 2)); extraPoints.add(1, points.get(points.size() - 1)); extraPoints.add(points.get(0)); extraPoints.add(points.get(1)); // Rotate the padded points so generated segment indices will align // with indices in the points ArrayList: Object first = extraPoints.get(0); extraPoints.remove(0); extraPoints.add(first); GeneralPath path = new GeneralPath(); int m = extraPoints.size(); ensureBases(m); segments.clear(); // Iterate over segments: for (int i = 3; i < m - 1; i++) { Polynomial xNum = new Polynomial(0); Polynomial yNum = new Polynomial(0); Polynomial xDen = new Polynomial(0); Polynomial yDen = new Polynomial(0); // Iterate over control points: for (int j = 0; j < m; j++) { Point2D p = (Point2D) extraPoints.get(j); BasisFunction basis = (BasisFunction) Bases.get(j); double px = p.getX(); double py = p.getY(); Polynomial xSegNum = basis.getSegment(i).multiply(px * Weight); Polynomial ySegNum = basis.getSegment(i).multiply(py * Weight); Polynomial xSegDen = basis.getSegment(i).multiply(Weight); Polynomial ySegDen = basis.getSegment(i).multiply(Weight); xNum = xNum.add(xSegNum); yNum = yNum.add(ySegNum); xDen = xDen.add(xSegDen); yDen = yDen.add(ySegDen); } Shape curve = Polynomial.createRationalShape(xNum, xDen, yNum, yDen, i, i + 1, .1); segments.add(curve); path.append(curve, true); } path.closePath(); shape = path; }