* @since 1.0.0 */ private array $points = []; /** * Constructor. * * @param array $points Points to create the interpolation with * * @since 1.0.0 */ public function __construct(array $points) { $this->points = $points; } /** * {@inheritdoc} */ public function interpolate(int | float $x) : float { $n = \count($this->points); $result = 0.0; for ($i = 0; $i < $n; ++$i) { $solve = $this->points[$i]['y']; for ($j = 0; $j < $n; ++$j) { if ($j !== $i) { $solve *= ($x - $this->points[$j]['x']) / ($this->points[$i]['x'] - $this->points[$j]['x']); } } $result += $solve; } return $result; } }