PHP Class MathPHP\NumericalAnalysis\RootFinding\BisectionMethod

In numerical analysis, the Bisection method is a method for finding successively better approximations to the roots (or zeroes) of a continuous, real-valued function f(x). It starts with two points $a and $b, such that f($a) and f($b) have different signs (one is positive, one is negative). This lets us use the intermediate value theorem to prove that there is a root $p such that p is between $a and $b. We initially set $p to be the average of $a and $b and analyze the result of f($p). Based on the sign, we construct a new $p that is either the average of $a and the original $p, or the average of the original $p and $b. We continue doing this until our function evaluation f($p) is within the tolerance set on our input. https://en.wikipedia.org/wiki/Bisection_method
Show file Open project: markrogoyski/math-php

Public Methods

Method Description
solve ( callable $function, number $a, number $b, number $tol ) : number Use the Bisection Method to find the x which produces $function(x) = 0.

Private Methods

Method Description
validate ( callable $function, number $a, number $b, number $tol ) Verify the input arguments are valid for correct use of the bisection method. If the tolerance is less than zero, an Exception will be thrown.

Method Details

solve() public static method

Use the Bisection Method to find the x which produces $function(x) = 0.
public static solve ( callable $function, number $a, number $b, number $tol ) : number
$function callable f(x) callback function
$a number The start of the interval which contains a root
$b number The end of the interval which contains a root
$tol number Tolerance; How close to the actual solution we would like.
return number