作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我需要实现一个从三个点对指数曲线进行插值的函数,但我不确定该怎么做。
我有一个图表,其中 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);
?>
输出
关于php - 指数函数算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25898522/
我需要在帮助行泰勒的帮助下实现递归函数指数函数(e^x):e^x = 1 + x + x2/2! + x3/3! + ...但我不明白我做错了什么我有下一个代码: function fact(n){
我正在尝试检查一个字符串是否包含带有 e^x 或 e^(any #, including negative)x 的东西,但我不太清楚出来。这是我尝试过的: if(str.matches("^(e^x)
我是一名优秀的程序员,十分优秀!