org.apache.commons.math.analysis.polynomials
public class PolynomialFunctionLagrangeForm extends java.lang.Object implements UnivariateRealFunction
The approximated function should be smooth enough for Lagrange polynomial to work well. Otherwise, consider using splines instead.
Modifier and Type | Field and Description |
---|---|
private double[] |
coefficients
The coefficients of the polynomial, ordered by degree -- i.e.
|
private boolean |
coefficientsComputed
Whether the polynomial coefficients are available.
|
private double[] |
x
Interpolating points (abscissas).
|
private double[] |
y
Function values at interpolating points.
|
Constructor and Description |
---|
PolynomialFunctionLagrangeForm(double[] x,
double[] y)
Construct a Lagrange polynomial with the given abscissas and function
values.
|
Modifier and Type | Method and Description |
---|---|
protected void |
computeCoefficients()
Calculate the coefficients of Lagrange polynomial from the
interpolation data.
|
int |
degree()
Returns the degree of the polynomial.
|
static double |
evaluate(double[] x,
double[] y,
double z)
Evaluate the Lagrange polynomial using
Neville's Algorithm.
|
double[] |
getCoefficients()
Returns a copy of the coefficients array.
|
double[] |
getInterpolatingPoints()
Returns a copy of the interpolating points array.
|
double[] |
getInterpolatingValues()
Returns a copy of the interpolating values array.
|
double |
value(double z)
Compute the value for the function.
|
static void |
verifyInterpolationArray(double[] x,
double[] y)
Verifies that the interpolation arrays are valid.
|
private double[] coefficients
private final double[] x
private final double[] y
private boolean coefficientsComputed
public PolynomialFunctionLagrangeForm(double[] x, double[] y) throws java.lang.IllegalArgumentException
The constructor makes copy of the input arrays and assigns them.
x
- interpolating pointsy
- function values at interpolating pointsjava.lang.IllegalArgumentException
- if input arrays are not validpublic double value(double z) throws FunctionEvaluationException
value
in interface UnivariateRealFunction
z
- the point for which the function value should be computedFunctionEvaluationException
- if the function evaluation failspublic int degree()
public double[] getInterpolatingPoints()
Changes made to the returned copy will not affect the polynomial.
public double[] getInterpolatingValues()
Changes made to the returned copy will not affect the polynomial.
public double[] getCoefficients()
Changes made to the returned copy will not affect the polynomial.
Note that coefficients computation can be ill-conditioned. Use with caution and only when it is necessary.
public static double evaluate(double[] x, double[] y, double z) throws DuplicateSampleAbscissaException, java.lang.IllegalArgumentException
This function is made public static so that users can call it directly without instantiating PolynomialFunctionLagrangeForm object.
x
- the interpolating points arrayy
- the interpolating values arrayz
- the point at which the function value is to be computedDuplicateSampleAbscissaException
- if the sample has duplicate abscissasjava.lang.IllegalArgumentException
- if inputs are not validprotected void computeCoefficients() throws java.lang.ArithmeticException
Note this computation can be ill-conditioned. Use with caution and only when it is necessary.
java.lang.ArithmeticException
- if any abscissas coincidepublic static void verifyInterpolationArray(double[] x, double[] y) throws java.lang.IllegalArgumentException
The arrays features checked by this method are that both arrays have the same length and this length is at least 2.
The interpolating points must be distinct. However it is not verified here, it is checked in evaluate() and computeCoefficients().
x
- the interpolating points arrayy
- the interpolating values arrayjava.lang.IllegalArgumentException
- if not validevaluate(double[], double[], double)
,
computeCoefficients()
Copyright (c) 2003-2013 Apache Software Foundation