MathPHP\NumericalAnalysis\RootFinding\SecantMethod::solve PHP Метод

solve() публичный статический Метод

Use the Secant Method to find the x which produces $f(x) = 0 by calculating the average change between our initial approximations and moving our approximations closer to the root.
public static solve ( callable $function, number $p₀, number $p₁, number $tol ) : number
$function callable f(x) callback function
$p₀ number First initial approximation
$p₁ number Second initial approximation
$tol number Tolerance; How close to the actual solution we would like.
Результат number
    public static function solve(callable $function, $p₀, $p₁, $tol)
    {
        // Validate input arguments
        self::validate($p₀, $p₁, $tol);
        do {
            $q₀ = $function($p₀);
            $q₁ = $function($p₁);
            $slope = ($q₁ - $q₀) / ($p₁ - $p₀);
            $p = $p₁ - $q₁ / $slope;
            $dif = abs($p - $p₁);
            $p₀ = $p₁;
            $p₁ = $p;
        } while ($dif > $tol);
        return $p;
    }
SecantMethod