Package org.ddogleg.solver
Class Polynomial
java.lang.Object
org.ddogleg.solver.Polynomial
Data structure for storing polynomials. Internally the coefficients are stored in an array from lowest degree
to highest:
f(x) = c[0] + c[1]*x + ... + c[n]*xn-1
f(x) = c[0] + c[1]*x + ... + c[n]*xn-1
-
Field Summary
-
Constructor Summary
ConstructorDescriptionPolynomial
(int maxCoefficients) Creates a polynomial which can hold the specified number of coefficients.Polynomial
(Polynomial original) -
Method Summary
Modifier and TypeMethodDescriptionint
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 numbersdouble
get
(int i) double[]
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 polynomialvoid
setTo
(double[] coefficients, int size) void
setTo
(Polynomial source) int
size()
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[0] + c[1]*x + ...void
zero()
-
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
-
-
Method Details
-
wrap
Wraps the polynomial around the array:
f(x) = c[0] + c[1]*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
-
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
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
-
print
public void print() -
getCoefficients
public double[] getCoefficients() -
size
public int size() -
get
public double get(int i)
-