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

Base class for numerical differentiation techniques. More...

Inheritance diagram for MathPHP\NumericalAnalysis\NumericalDifferentiation\NumericalDifferentiation:
Inheritance graph
[legend]

Static Public Member Functions

static differentiate ($target, $source,... $args)
 
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)
 Validate that there are a set number of input arrays (points), that each point array has precisely two numbers, and that no two points share the same first number (x-component) More...
 
static isSpacingConstant (array $sorted)
 Ensures that the length of each subinterval is equal, or equivalently, that the spacing between each point is equal. More...
 
static isTargetInPoints ($target, array $sorted)
 Ensures that our target is the x-component of one of the points we supply. More...
 

Public Attributes

const X = 0
 
const Y = 1
 

Static Protected Member Functions

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

Base class for numerical differentiation techniques.

Numerical differentiation techniques are used to approximate the derivative of a function at an input value.

This class gives each technique a set of common tools, and requires each technique to define a differentiate() method to approximate the derivative of a function at an input value.

Member Function Documentation

◆ functionToPoints()

static MathPHP\NumericalAnalysis\NumericalDifferentiation\NumericalDifferentiation::functionToPoints ( callable  $function,
  $start,
  $end,
  $n 
)
staticprotected

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

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

◆ getPoints()

static MathPHP\NumericalAnalysis\NumericalDifferentiation\NumericalDifferentiation::getPoints (   $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: start, end, and n. Example: [0, 8, 5]. If $source is a set of arrays, $args will default to [].
Returns
array
Exceptions
Exceptionif $source is not callable or a set of arrays

◆ isSpacingConstant()

static MathPHP\NumericalAnalysis\NumericalDifferentiation\NumericalDifferentiation::isSpacingConstant ( array  $sorted)
static

Ensures that the length of each subinterval is equal, or equivalently, that the spacing between each point is equal.

Parameters
array$sortedPoints sorted by (increasing) x-component
Exceptions
Exceptionif the spacing between any two points is not equal to the average spacing between every point

◆ isTargetInPoints()

static MathPHP\NumericalAnalysis\NumericalDifferentiation\NumericalDifferentiation::isTargetInPoints (   $target,
array  $sorted 
)
static

Ensures that our target is the x-component of one of the points we supply.

Parameters
number$targetThe value at which we are approximating the derivative
array$sortedPoints sorted by (increasing) x-component
Exceptions
Exceptionif $target is not contained in the array of our x-components

◆ sort()

static MathPHP\NumericalAnalysis\NumericalDifferentiation\NumericalDifferentiation::sort ( array  $points)
staticprotected

Sorts our coordinates (arrays) by their x-component (first number) such that consecutive coordinates have an increasing x-component.

Parameters
array$points
Returns
array

◆ validate()

static MathPHP\NumericalAnalysis\NumericalDifferentiation\NumericalDifferentiation::validate ( array  $points,
  $degree 
)
static

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

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

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