PHP Класс MathPHP\Functions\Piecewise

https://en.wikipedia.org/wiki/Piecewise
Показать файл Открыть проект

Открытые методы

Метод Описание
__construct ( array $intervals, array $functions ) Validate that our inputs satisfy the conditions of a piecewise function, and then assign our inputs as the object parameters.
__invoke ( number $x₀ ) : number When a callback function is being evaluated at a specific point, find the the corresponding function for that point in the domain, and then return the function evaluated at that point. If no function is found, throw an Exception.
getFunction ( number $x ) : mixed Find which subinterval our input value is contained within, and then return the function that corresponds to that subinterval. If no subinterval is found such that our input is contained within it, a false is returned.

Описание методов

__construct() публичный метод

In our $intervals array, each interval should contain two numbers [a, b]. We can optionally add two booleans to an interval, signifying the openness of a and b, respectfully (true means open, false means closed). If boolean arguments are not supplied, the interval will be assumed to be closed. Examples: 1. [0, 2, true, false] means an interval from 0 to 2, where 0 is open (exclusive) and 2 is closed (inclusive). 2. [-10, 10] means an closed (inclusive) interval from -10 to 10 A number of conditions need to be met for a piecewise function: o We must provide the same number of intervals as callback functions o Each function in our $functions array needs to be callable o Each interval must contain precisely 2 numbers, optionally 2 o An interval defined as a point (e.g. [2, 2]) must be closed at both ends o The numbers in an interval must be increasing. Given [a, b] then b >= a. o Two intervals cannot overlap. This means that if two intervals share a start and end-point, the point must be closed on both sides. Also, we cannot start or end an interval in the middle of another interval.
public __construct ( array $intervals, array $functions )
$intervals array Array of intervals Example: [[-10, 0, false, true], [0, 2], [3, 10]]
$functions array Array of callback functions

__invoke() публичный метод

When a callback function is being evaluated at a specific point, find the the corresponding function for that point in the domain, and then return the function evaluated at that point. If no function is found, throw an Exception.
public __invoke ( number $x₀ ) : number
$x₀ number The value at which we are evaluating our piecewise function
Результат number The specific function evaluated at $x₀

getFunction() публичный метод

Find which subinterval our input value is contained within, and then return the function that corresponds to that subinterval. If no subinterval is found such that our input is contained within it, a false is returned.
public getFunction ( number $x ) : mixed
$x number The value at which we are searching for a subinterval that contains it, and thus has a corresponding function.
Результат mixed Returns the function that contains $x in its domain, or false