private function lagrangeInterp($x, $table)
    {
        $sum = 0;
        for ($i = 0; $i < count($table); $i++) {
            $xi   = $table[$i]['x'];
            $prod = 1;

            for ($j = 0; $j < count($table); $j++) {
                if ($i != $j) {
                    $xj = $table[$j]['x'];
                    $prod *= ($x - $xj) / ($xi - $xj);
                }
            }

            $sum += $table[$i]['y'] * $prod;
        }

        return $sum;
    }