PHP Class MathPHP\NumericalAnalysis\RootFinding\FixedPointIteration

In numerical analysis, the fixed point method is a method for finding successively better approximations to the roots (or zeroes) of a continuous, real-valued function f(x). For fixed point iteration, we require that we can rewrite f(x) = 0 as g(x) = x for some continuous, real-valued function g(x). We then determine some interval [a, b] to which we will iterate over. To guarantee a root is in [a, b], we should chose [a, b] such that g(x) is continuous and g(x) is in [a, b], for all x in [a, b]. To guarantee our iteration will converge to a single root, we should choose [a, b] such that for some 0 < k < 1, the magnitude of the derivative |g'(x)| < k on all x in [a, b]. https://en.wikipedia.org/wiki/Fixed-point_iteration
Show file Open project: markrogoyski/math-php

Public Methods

Method Description
solve ( callable $function, number $a, number $b, number $p, number $tol ) : number Use Fixed Point Iteration to find the x which produces f(x) = 0 by rewriting f(x) = 0 as g(x) = x, where g(x) is our input function.

Private Methods

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

Method Details

solve() public static method

Use Fixed Point Iteration to find the x which produces f(x) = 0 by rewriting f(x) = 0 as g(x) = x, where g(x) is our input function.
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