MathPHP\NumericalAnalysis\NumericalDifferentiation\NumericalDifferentiation::validate PHP Method

validate() public static method

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)
public static validate ( array $points, number $degree ) : boolean
$points array Array of arrays (points)
$degree number The number of input arrays
return boolean
    public static function validate(array $points, $degree) : bool
    {
        if (count($points) != $degree) {
            throw new Exception\BadDataException("You need to have {$degree} sets of coordinates (arrays) for this technique");
        }
        $x_coordinates = [];
        foreach ($points as $point) {
            if (count($point) !== 2) {
                throw new Exception\BadDataException('Each array needs to have have precisely two numbers, an x- and y-component');
            }
            $x_component = $point[self::X];
            if (in_array($x_component, $x_coordinates)) {
                throw new Exception\BadDataException('Not a function. Your input array contains more than one coordinate with the same x-component.');
            }
            array_push($x_coordinates, $x_component);
        }
        return true;
    }