public static solve ( callable $function, number $a, number $b, number $p, number $tol ) : number | ||
$function | callable | g(x) callback function, obtained by rewriting f(x) = 0 as g(x) = x |
$a | number | The start of the interval which contains a root |
$b | number | The end of the interval which contains a root |
$p | number | The initial guess of our root, in [$a, $b] |
$tol | number | Tolerance; How close to the actual solution we would like. |
return | number |
public static function solve(callable $function, $a, $b, $p, $tol)
{
// Validate input arguments
self::validate($a, $b, $p, $tol);
do {
$g⟮p⟯ = $function($p);
$dif = abs($g⟮p⟯ - $p);
$p = $g⟮p⟯;
} while ($dif > $tol);
return $p;
}