Start with a guess, then repeatedly update the guess until we're close enough to the desired solution.
use Haldayne\Fox\Improve;
$calculator = new Improve(
function ($guess) { return abs(($guess * $guess) - ($guess + 1)) < .00001; },
function ($guess) { return 1/$guess + 1; }
);
$phi = $calculator(1);
$calculator->getGuessHistory();
package | Haldayne |
---|
__construct(callable $decide, callable $update)
callable
Decides if the guess is good enough. Receives one argument, the current guess.
callable
Updates the guess to a new guess. Receives two arguments: the current guess and the current loop count, in that order.
__invoke(mixed $guess) : mixed
mixed
The initial guess
mixed
The calculated resultgetGuessHistory() : \Haldayne\Boost\Map
\Haldayne\Boost\Map
setMaximumIterations(integer|null $maxIterations) : void
By default, there is no limit.
integer
null
$decide
null
$guesses
null
$maxIterations
null
$update
null