math-php
Static Public Member Functions | Public Attributes | Static Protected Member Functions | List of all members
MathPHP\NumericalAnalysis\Interpolation\ClampedCubicSpline Class Reference

Clamped Cubic Spline Interpolating Polyonomial. More...

Inheritance diagram for MathPHP\NumericalAnalysis\Interpolation\ClampedCubicSpline:
Inheritance graph
[legend]
Collaboration diagram for MathPHP\NumericalAnalysis\Interpolation\ClampedCubicSpline:
Collaboration graph
[legend]

Static Public Member Functions

static interpolate ($source,... $args)
 Interpolate. More...
 
static getSplinePoints ($source, array $args=[])
 Determine where the input $source argument is a callback function, a set of arrays, or neither. More...
 
static validateSpline (array $points, $degree=2)
 Validate that there are enough input arrays (points), that each point array has precisely three numbers, and that no two points share the same first number (x-component) More...
 
- Static Public Member Functions inherited from MathPHP\NumericalAnalysis\Interpolation\Interpolation
static getPoints ($source, array $args=[])
 Determine where the input $source argument is a callback function, a set of arrays, or neither. More...
 
static validate (array $points, $degree=2)
 Validate that there are enough input arrays (points), that each point array has precisely two numbers, and that no two points share the same first number (x-component) More...
 

Public Attributes

const Y’ = 2
 
- Public Attributes inherited from MathPHP\NumericalAnalysis\Interpolation\Interpolation
const X = 0
 
const Y = 1
 

Static Protected Member Functions

static functionToSplinePoints (callable $function, callable $derivative, $start, $end, $n)
 Evaluate our callback function and derivative at n evenly spaced points on the interval between start and end. More...
 
- Static Protected Member Functions inherited from MathPHP\NumericalAnalysis\Interpolation\Interpolation
static functionToPoints (callable $function, $start, $end, $n)
 Evaluate our callback function at n evenly spaced points on the interval between start and end. More...
 
static sort (array $points)
 Sorts our coordinates (arrays) by their x-component (first number) such that consecutive coordinates have an increasing x-component. More...
 

Detailed Description

Clamped Cubic Spline Interpolating Polyonomial.

In numerical analysis, cubic splines are used for polynomial interpolation.

A cubic spline is a spline constructed of piecewise third-order polynomials which pass through a set of m control points." In the case of the Clamped cubic spline, the first derivative of piecewise polynomial is set to equal the first derivative of our input at the endpoints.

Cubic spline interpolation belongs to a collection of techniques that interpolate a function or a set of values, producing a continuous polynomial. In the case of the cubic spline, a piecewise function (polynomial) is produced. We can either directly supply a set of inputs and their corresponding outputs for said function, or if we explicitly know the function, we can define it as a callback function and then generate a set of points by evaluating that function at n points between a start and end point. We then use these values to interpolate our piecewise polynomial.

https://en.wikipedia.org/wiki/Spline_interpolation http://mathworld.wolfram.com/CubicSpline.html

Member Function Documentation

◆ functionToSplinePoints()

static MathPHP\NumericalAnalysis\Interpolation\ClampedCubicSpline::functionToSplinePoints ( callable  $function,
callable  $derivative,
  $start,
  $end,
  $n 
)
staticprotected

Evaluate our callback function and derivative at n evenly spaced points on the interval between start and end.

Parameters
callable$functionf(x) callback function
callable$derivativef'(x) callback function
number$startthe start of the interval
number$endthe end of the interval
number$nthe number of function evaluations
Returns
array

◆ getSplinePoints()

static MathPHP\NumericalAnalysis\Interpolation\ClampedCubicSpline::getSplinePoints (   $source,
array  $args = [] 
)
static

Determine where the input $source argument is a callback function, a set of arrays, or neither.

If $source is a callback function, run it through the functionToPoints() method with the input $args, and set $points to output array. If $source is a set of arrays, simply set $points to $source. If $source is neither, throw an Exception.

Todo:

Add method to verify function is continuous on our interval

Add method to verify input arguments are valid. Verify $start and $end are numbers, $end > $start, and $points is an integer > 1

Parameters
callable | array$sourceThe source of our approximation. Should be either a callback function or a set of arrays.
array$argsThe arguments of our callback function: derivative, start, end, and n. Example: [$derivative, 0, 8, 5]. If $source is a set of arrays, $args will default to [].
Returns
array
Exceptions
Exception

◆ interpolate()

static MathPHP\NumericalAnalysis\Interpolation\ClampedCubicSpline::interpolate (   $source,
  $args 
)
static

Interpolate.

Parameters
callable | array$sourceThe source of our approximation. Should be either a callback function or a set of arrays. Each array (point) contains precisely three numbers: x, y, and y' Example array: [[1,2,1], [2,3,0], [3,4,2]]. Example callback: function($x) {return $x**2;}
number... $args (Optional) An additonal callback: our first derivative, and arguments of our callback functions: start, end, and n. Example: approximate($source, $derivative, 0, 8, 5). If $source is a set of points, do not input any $args. Example: approximate($source).
Returns
Piecewise The interpolting (piecewise) polynomial, as an instance of Piecewise.

◆ validateSpline()

static MathPHP\NumericalAnalysis\Interpolation\ClampedCubicSpline::validateSpline ( array  $points,
  $degree = 2 
)
static

Validate that there are enough input arrays (points), that each point array has precisely three numbers, and that no two points share the same first number (x-component)

Parameters
array$pointsArray of arrays (points)
number$degreeThe miminum number of input arrays
Returns
bool
Exceptions
Exceptionif there are less than two points
Exceptionif any point does not contain three numbers
Exceptionif two points share the same first number (x-component)

The documentation for this class was generated from the following file: