org.ddogleg.solver
Class Polynomial
- java.lang.Object
-
- org.ddogleg.solver.Polynomial
-
public class Polynomial extends java.lang.ObjectData 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
-
-
Constructor Summary
Constructors Constructor and Description Polynomial(int maxCoefficients)Creates a polynomial which can hold the specified number of coefficients.Polynomial(Polynomial original)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description intcomputeDegree()Finds the power of the largest non-zero coefficient in the polynomial.doubleevaluate(double variable)Computes the polynomials output given the variable value Can handle infinite numbersdoubleget(int i)double[]getCoefficients()booleanisIdentical(Polynomial p, double tol)Checks to see if the coefficients of two polynomials are identical to within tolerance.voidprint()voidresize(int size)Change the maximum number of coefficients which can be stored inside this polynomialvoidsetTo(double[] coefficients, int size)voidsetTo(Polynomial source)intsize()java.lang.StringtoString()voidtruncateZeros(double tol)Prunes zero coefficients from the end of a sequence.static Polynomialwrap(double... coefficients)Wraps the polynomial around the array:
f(x) = c[0] + c[1]*x + ...voidzero()
-
-
-
Constructor Detail
-
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 Detail
-
wrap
public static Polynomial wrap(double... coefficients)
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
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 java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
print
public void print()
-
getCoefficients
public double[] getCoefficients()
-
size
public int size()
-
get
public double get(int i)
-
-
DataMelt 3.0 © DataMelt by jWork.ORG