The Polynomial class provides a framework for representing and manipulating polynomials in one variable. It supports essential mathematical operations such as addition, multiplication, differentiation, and evaluation. The class is designed for single-threaded use.
Functionality
This class enables the addition of polynomials or individual terms, allowing for the construction of complex polynomial expressions. It supports multiplication with other polynomials or individual terms, making it versatile for algebraic operations. Additionally, users can find roots of a polynomial using Newton's method, which provides precision control through configurable error margins and iteration limits.
The class also offers methods to compute and retrieve the derivative of a polynomial. The derivative can be further evaluated at specific points to analyze its behavior. Users can reset the polynomial to zero when needed, providing a clean state for new calculations.
Returns:Number The root value after the specified number of iterations or as soon as the error condition is satisfied.
Returns Double.NaN if the derivative was zero during the computation.
Sample
// Model the quadratic equation -x^2 + 4x + 0.6 = 0
var eq = plugins.amortization.newPolynomial();
eq.addTerm(-1, 2);
eq.addTerm(4, 1);
eq.addTerm(0.6, 0);
// Find the roots of the equation.
r1 = eq.findRoot(100, 1E-5, 1000);
r2 = eq.findRoot(-100, 1E-5, 1000);
application.output("eq(" + r1 + ")=" + eq.getValue(r1));
application.output("eq(" + r2 + ")=" + eq.getValue(r2));
// Find the minimum/maximum point by zeroing the first derivative.
var deriv = eq.getDerivative();
rd = deriv.findRoot(0, 1E-5, 1000);
application.output("Min/max point: " + rd);
application.output("Min/max value: " + eq.getValue(rd));
if (deriv.getDerivativeValue(rd) < 0) application.output("Max point.");
else application.output("Min point.");
getDerivative()
Returns a polynomial that holds the derivative of this polynomial.
Returns:Polynomial A polynomial representing the derivative of this polynomial.
Sample
// Model the quadratic equation -x^2 + 4x + 0.6 = 0
var eq = plugins.amortization.newPolynomial();
eq.addTerm(-1, 2);
eq.addTerm(4, 1);
eq.addTerm(0.6, 0);
// Find the roots of the equation.
r1 = eq.findRoot(100, 1E-5, 1000);
r2 = eq.findRoot(-100, 1E-5, 1000);
application.output("eq(" + r1 + ")=" + eq.getValue(r1));
application.output("eq(" + r2 + ")=" + eq.getValue(r2));
// Find the minimum/maximum point by zeroing the first derivative.
var deriv = eq.getDerivative();
rd = deriv.findRoot(0, 1E-5, 1000);
application.output("Min/max point: " + rd);
application.output("Min/max value: " + eq.getValue(rd));
if (deriv.getDerivativeValue(rd) < 0) application.output("Max point.");
else application.output("Min point.");
getDerivativeValue(x)
Returns the value of the derivative of this polynomial in a certain point.