Polynomial Module

Calculates polynomials that interpolatethe two dimensional data. The polynomial order is equal to the number of data points - 1.

In general a polynomial with degree = datapointNumber - 1 is flexible enough to interpolate all datapoints. But polynomial regression with degree = datapointNumber - 1 cannot be used for polynomial interpolation because the least squares approach is not sufficient to converge interpolating.

Types

Type Description

PolynomialCoef

contains polynomial coefficients sorted from intercept to highest order factor

Functions and values

Function or value Description

differentiate coef level

Full Usage: differentiate coef level

Parameters:
    coef : PolynomialCoef - polynomial coefficients (e.g. determined by Polynomial.coefficients), sorted as [constant;linear;quadratic;...]
    level : int - Level of differentiation: 1 = fst derivative, 2 = snd derivative, ... .

Returns: PolynomialCoef Coefficients of the derivative polynomial

Determines the coefficients of the derivative of the given polynomial. Level 1 = fst derivative, level 2 = snd derivative, ... . The resulting polynomial is `level` degrees lower than the original polynomial.

coef : PolynomialCoef

polynomial coefficients (e.g. determined by Polynomial.coefficients), sorted as [constant;linear;quadratic;...]

level : int

Level of differentiation: 1 = fst derivative, 2 = snd derivative, ... .

Returns: PolynomialCoef

Coefficients of the derivative polynomial

Example

 
 // e.g. days since a certain event
 let xData = vector [|1.;2.;3.;4.;5.;6.|]
 // e.g. temperature measured at noon of the days specified in xData 
 let yData = vector [|4.;7.;9.;8.;7.;9.;|]
 
 // Estimate the polynomial coefficients. In Interpolation the order is equal to the data length - 1.
 let coefficients = 
     Interpolation.Polynomial.coefficients xData yData 
 
 // Get curvature function coefficients. 
 Interpolation.Polynomial.differentiate coefficients 2

getDerivative coef level x

Full Usage: getDerivative coef level x

Parameters:
    coef : PolynomialCoef - polynomial coefficients (e.g. determined by Polynomial.coefficients), sorted as [constant;linear;quadratic;...]
    level : int - depth of derivative: 1 = slope, 2 = curvature, ...
    x : float - x value of which the corresponding y value should be predicted

Returns: float predicted derivative with given polynomial coefficients at X=x

calculates derivative values at X=x with given polynomial coefficients. Level 1 = fst derivative; Level2 = snd derivative ...

coef : PolynomialCoef

polynomial coefficients (e.g. determined by Polynomial.coefficients), sorted as [constant;linear;quadratic;...]

level : int

depth of derivative: 1 = slope, 2 = curvature, ...

x : float

x value of which the corresponding y value should be predicted

Returns: float

predicted derivative with given polynomial coefficients at X=x

Example

 
 // e.g. days since a certain event
 let xData = vector [|1.;2.;3.;4.;5.;6.|]
 // e.g. temperature measured at noon of the days specified in xData 
 let yData = vector [|4.;7.;9.;8.;7.;9.;|]
 
 // Estimate the polynomial coefficients. In Interpolation the order is equal to the data length - 1.
 let coefficients = 
     Interpolation.Polynomial.coefficients xData yData 
 
 // Predict the curvature of the interpolating function at midnight between day 1 and 2. 
 Interpolation.Polynomial.getDerivative coefficients 2 1.5

getIntegralBetween coef x1 x2

Full Usage: getIntegralBetween coef x1 x2

Parameters:
    coef : PolynomialCoef - polynomial coefficients (e.g. determined by Polynomial.coefficients), sorted as [constant;linear;quadratic;...]
    x1 : float - start x value
    x2 : float - end x value

Returns: float integral of the polynomial in the range defined by x1 and x2

calculates the area under the curve from x=x1 to x=x2 with given polynomial coefficients.

coef : PolynomialCoef

polynomial coefficients (e.g. determined by Polynomial.coefficients), sorted as [constant;linear;quadratic;...]

x1 : float

start x value

x2 : float

end x value

Returns: float

integral of the polynomial in the range defined by x1 and x2

Example

 
 // e.g. days since a certain event
 let xData = vector [|1.;2.;3.;4.;5.;6.|]
 // e.g. temperature measured at noon of the days specified in xData 
 let yData = vector [|4.;7.;9.;8.;7.;9.;|]
 
 // Estimate the polynomial coefficients. In Interpolation the order is equal to the data length - 1.
 let coefficients = 
     Interpolation.Polynomial.coefficients xData yData 
 
 // Get area under the curve between x=0 and x=2. 
 Interpolation.Polynomial.getIntegral coefficients 0. 2.

integrate coef

Full Usage: integrate coef

Parameters:
    coef : PolynomialCoef - polynomial coefficients (e.g. determined by Polynomial.coefficients), sorted as [constant;linear;quadratic;...]

Returns: PolynomialCoef Coefficients of the integral polynomial

Determines the coefficients of the integral of the given polynomial. The resulting polynomial is one degree higher than the original polynomial.

coef : PolynomialCoef

polynomial coefficients (e.g. determined by Polynomial.coefficients), sorted as [constant;linear;quadratic;...]

Returns: PolynomialCoef

Coefficients of the integral polynomial

Example

 
 // e.g. days since a certain event
 let xData = vector [|1.;2.;3.;4.;5.;6.|]
 // e.g. temperature measured at noon of the days specified in xData 
 let yData = vector [|4.;7.;9.;8.;7.;9.;|]
 
 // Estimate the polynomial coefficients. In Interpolation the order is equal to the data length - 1.
 let coefficients = 
     Interpolation.Polynomial.coefficients xData yData 
 
 // Get integral function coefficients. 
 Interpolation.Polynomial.integrate coefficients

interpolate xData yData

Full Usage: interpolate xData yData

Parameters:
    xData : Vector<float> - Note: Must not contain duplicate x values (use Approximation.regularizeValues to preprocess data!)
    yData : Vector<float> - vector of y values

Returns: PolynomialCoef vector of polynomial coefficients sorted as [constant;linear;quadratic;...]

Calculates the polynomial coefficients for interpolating the given unsorted data.

No duplicates allowed!

xData : Vector<float>

Note: Must not contain duplicate x values (use Approximation.regularizeValues to preprocess data!)

yData : Vector<float>

vector of y values

Returns: PolynomialCoef

vector of polynomial coefficients sorted as [constant;linear;quadratic;...]

Example

 
 // e.g. days since a certain event
 let xData = vector [|1.;2.;3.;4.;5.;6.|]
 // e.g. e.g. temperature measured at noon of the days specified in xData 
 let yData = vector [|4.;7.;9.;8.;7.;9.;|]
 
 // Estimate the polynomial coefficients. In Interpolation the order is equal to the data length - 1.
 let coefficients = 
     Interpolation.Polynomial.coefficients xData yData

predict coef x

Full Usage: predict coef x

Parameters:
    coef : PolynomialCoef - polynomial coefficients (e.g. determined by Polynomial.coefficients), sorted as [constant;linear;quadratic;...]
    x : float - x value of which the corresponding y value should be predicted

Returns: float predicted y value with given polynomial coefficients at X=x

takes polynomial coefficients and x value to predict the corresponding interpolating y value

coef : PolynomialCoef

polynomial coefficients (e.g. determined by Polynomial.coefficients), sorted as [constant;linear;quadratic;...]

x : float

x value of which the corresponding y value should be predicted

Returns: float

predicted y value with given polynomial coefficients at X=x

Example

 
 // e.g. days since a certain event
 let xData = vector [|1.;2.;3.;4.;5.;6.|]
 // e.g. temperature measured at noon of the days specified in xData 
 let yData = vector [|4.;7.;9.;8.;7.;9.;|]
 
 // Estimate the polynomial coefficients. In Interpolation the order is equal to the data length - 1.
 let coefficients = 
     Interpolation.Polynomial.coefficients xData yData 
 
 // Predict the temperature value at midnight between day 1 and 2. 
 Interpolation.Polynomial.fit coefficients 1.5