p4/excel-goalseek

用于在PHP中模拟goalseek函数的实用工具

v2.0.0 2021-09-02 19:30 UTC

This package is auto-updated.

Last update: 2024-09-09 02:01:03 UTC


README

Scrutinizer Code Quality Code Coverage Build Status Code Intelligence Status

此实用工具用于在PHP中模拟goalseek函数。这个分支是为特定项目创建的,不保证保持任何BC(向后兼容性)。

此库是基于PHP-Excel-GoalSeek的分支。

安装

使用来自packagist的包。

composer require p4/excel-goalseek

使用方法

//Define function which for which the value should be found
$callbackTest = function callbackTest($input) {
    $inputForCallbackTest2 = $input * 8;
    return $inputForCallbackTest2 - 12;
};

//Instantiate goal seek class
$goalseek = new ExcelGoalSeek();
//$goalseek->debug = true;

//I want to know which input needs callbackTest to give me 301
$expected_result = 300;

//Calculate the input to get you goal, with accuracy
$input = $goalseek->calculate($callbackTest, $expected_result, 5);

//Voilá!
echo "\$input: " . $input . "<br />";

//Let's test our input it is close
$actual_result = $callbackTest($input);
//Searched result of function
echo "Searched result of $callbackTest(\$input) = " . $expected_result . "<br />";
//Actual result of function with calculated goalseek
echo "Actual result of $callbackTest(" . $input . ") = " . $actual_result . "<br />";
//If difference is too high, you can improve the class and send me it your modifications ;)
echo "Difference = " . ($actual_result - $expected_result);

测试

$ phpunit

贡献

请参阅CONTRIBUTING以获取详细信息。

致谢

许可证

MIT许可证(MIT)。有关更多信息,请参阅许可证文件