gpt4 book ai didi

php - 指数函数算法

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:25:55 26 4
gpt4 key购买 nike

我需要实现一个从三个点对指数曲线进行插值的函数,但我不确定该怎么做。

我有一个图表,其中 Y 轴为百分比,0 到 100%,X 为 0 到 10。

我唯一知道的点是 (50,7)、(100,10) 和 (0,0)。

我知道我可以创建一个包含百分比和值的数组并循环遍历它,但这并不是“正确”的做法。有没有更直接的算法?

最佳答案

我会使用公式:

partial : total = % : 100
partial (the value) = (total * %) / 100

代码

<?php

$points = array("8%,67%","36%,74%","73%,13%");


function return_value($percentage,$total) {
$value = ($total * $percentage) / 100.0;
return $value;
}

function evaluate_points($points) {
$max_x = 100.0; // As float value
$max_y = 10.0; // As float value
for ($point = 0; $point < count($points); $point++) {
//Replace the % sign
$points[$point] = str_replace("%", "", $points[$point]);

$point_percentages = explode(",", $points[$point]);
$x_percentage = $point_percentages[0];
$y_percentage = $point_percentages[1];
echo("The value for x is : ".return_value($x_percentage,$max_x) ."<br>");
echo("The value for y is : ".return_value($y_percentage,$max_y). "<br><br>");
}
}

evaluate_points($points);


?>

输出

enter image description here

关于php - 指数函数算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25898522/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com