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;
    }
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;
    }
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 ; }
Interpolates the y-value at a given x-value within a dataset using the
Lagrange interpolation algorithm

@param  float $x     x-value to interpolate
@param  array $table Dataset

@return float        interpolated value of y
Interpolates the y - value at a given x - value within a dataset using the Lagrange interpolation algorithm