Class Polynomial

java.lang.Object
org.ddogleg.solver.Polynomial

public class Polynomial
extends Object
Data structure for storing polynomials. Internally the coefficients are stored in an array from lowest degree to highest:
f(x) = c + c*x + ... + c[n]*xn-1
• Field Summary

Fields
Modifier and Type Field Description
double[] c
int size
• Constructor Summary

Constructors
Constructor Description
Polynomial​(int maxCoefficients)
Creates a polynomial which can hold the specified number of coefficients.
Polynomial​(Polynomial original)
• Method Summary

Modifier and Type Method Description
int computeDegree()
Finds the power of the largest non-zero coefficient in the polynomial.
double evaluate​(double variable)
Computes the polynomials output given the variable value Can handle infinite numbers
double get​(int i)
double[] getCoefficients()
boolean isIdentical​(Polynomial p, double tol)
Checks to see if the coefficients of two polynomials are identical to within tolerance.
void print()
void resize​(int size)
Change the maximum number of coefficients which can be stored inside this polynomial
void setTo​(double[] coefficients, int size)
void setTo​(Polynomial source)
int size()
String toString()
void truncateZeros​(double tol)
Prunes zero coefficients from the end of a sequence.
static Polynomial wrap​(double... coefficients)
Wraps the polynomial around the array:
f(x) = c + c*x + ...
void zero()

Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
• Field Details

• c

public double[] c
• size

public int size
• Constructor Details

• Polynomial

public Polynomial​(int maxCoefficients)
Creates a polynomial which can hold the specified number of coefficients. Note this is the polynomial's degree+1.
Parameters:
maxCoefficients - The largest number of coefficients which can be stored. Also the initial size of the polynomial.
• Polynomial

public Polynomial​(Polynomial original)
• Method Details

• wrap

public static Polynomial wrap​(double... coefficients)
Wraps the polynomial around the array:
f(x) = c + c*x + ... + c[n]*xn-1
Parameters:
coefficients - Polynomial coefficients
Returns:
new instance of a polyonimial which is identical to the input array
• evaluate

public double evaluate​(double variable)
Computes the polynomials output given the variable value Can handle infinite numbers
Returns:
Output
• setTo

public void setTo​(Polynomial source)
• setTo

public void setTo​(double[] coefficients, int size)
• resize

public void resize​(int size)
Change the maximum number of coefficients which can be stored inside this polynomial
Parameters:
size - New maximum number of coefficients.
• zero

public void zero()
• computeDegree

public int computeDegree()
Finds the power of the largest non-zero coefficient in the polynomial. If all the coefficients are zero or if there is only the constant term, zero is returned.
Returns:
Degree of the polynomial
• isIdentical

public boolean isIdentical​(Polynomial p, double tol)
Checks to see if the coefficients of two polynomials are identical to within tolerance. If the lengths of the polynomials are not the same then the extra coefficients in the longer polynomial must be within tolerance of zero.
Parameters:
p - Polynomial that this polynomial is being compared against.
tol - Similarity tolerance. Try 1e-15 for high confidence
Returns:
true if the two polynomials are identical to within tolerance.
• truncateZeros

public void truncateZeros​(double tol)
Prunes zero coefficients from the end of a sequence. A coefficient is zero if its absolute value is less than or equal to tolerance.
Parameters:
tol - Tolerance for zero. Try 1e-15
• toString

public String toString()
Overrides:
toString in class Object
• print

public void print()
• getCoefficients

public double[] getCoefficients()
• size

public int size()
• get

public double get​(int i)