四虎精品视频-四虎精品成人免费网站-四虎黄色网-四虎国产视频-国产免费91-国产蜜臀97一区二区三区

PHP寫的求多項式導(dǎo)數(shù)的函數(shù)代碼

復(fù)制代碼 代碼如下:
<?php
function getDerivativeByFormulaAndXDATA($formula, $x_data){
$xArray = explode("+", $formula);
$Derivative = 0;
foreach ($xArray as $x_record) {
$tmpArray = explode("x^", $x_record);
if(count($tmpArray) == 2){
$coefficient = $tmpArray[0]==""?1:$tmpArray[0];
$exp = $tmpArray[1];
}
//constant
else {
$coefficient = $tmpArray[0];
$exp = 0;
}
$Derivative += $coefficient*$exp*pow($x_data,$exp-1);
}
return $Derivative;
}
function getValueByFormulaAndXDATA($formula, $x_data){
$xArray = explode("+", $formula);
$y_data = 0;
foreach ($xArray as $x_record) {
$tmpArray = explode("x^", $x_record);
if(count($tmpArray) == 2){
$coefficient = $tmpArray[0]==""?1:$tmpArray[0];
$exp = $tmpArray[1];
}
//constant
else {
$coefficient = $tmpArray[0];
$exp = 0;
}
$y_data += $coefficient*pow($x_data,$exp);
}
return $y_data;
}
function getMaxDerivativeByFormulaAndXDATAS($formula, $x_datas, &$matchs){
$derivatives = array();
$max_derivative = 0;
foreach ($x_datas as $x_data) {
$derivative = getDerivativeByFormulaAndXDATA($formula, $x_data);
$derivatives[$x_data] = $derivative;
$max_derivative = $max_derivative>=abs($derivative)?$max_derivative:abs($derivative);
//printf("x=%f, derivative=%f /n",$x_data, $derivative);
}
$matchs = array();
foreach ($derivatives as $x_data=>$derivative) {
if(abs($derivative) == $max_derivative){
$matchs[] = $x_data;
}
}
printf("max derivative=%f/n",$max_derivative);
foreach ($matchs as $x_match) {
printf(" derivative=%f when x=%f/n",$derivatives[$x_match], $x_match);
}
}
//notice the format of formula: ax^b if b=0 could omit except coefficient a, if a=1 could omit coefficient
$formula = "x^2+2x^1+1";
print "The formula is $formula /n";
//printf("Derivative of 2 is %f /n",getDerivativeByFormulaAndXDATA($formula, 3.2));
//print getValueByFormulaAndXDATA($formula, 3.2)."/n";
$sampleData = array(-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,1,2,3,4,5,6,7,8,9,10,11,12);
foreach ($sampleData as $x_data) {
$str.=$x_data.", ";
}
print "sample x values: $str /n";
getMaxDerivativeByFormulaAndXDATAS($formula, $sampleData, $matchs)."/n";
?>

the output will be:
sample x values: -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
max derivative=26.000000
derivative=26.000000 when x=12.000000

php技術(shù)PHP寫的求多項式導(dǎo)數(shù)的函數(shù)代碼,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 东方电视台节目表今日节目| 比基尼裸体| 破天荒| 电视剧《惊蛰》演员表| 春娇与志明2| 等着我 综艺| 德兰| 快播电影网| 植田圭辅| 九宫格数独100题及答案| 周秀娜全部三级视频| 亚洲第一区se| 让娜迪尔曼| 视频污| 《猫女的诅咒》美国电影| bobo视频| 猛鬼追魂| 陈一龙是哪部电视剧| 美丽在唱歌 电影| 奶粉罐回收多少钱一个| 同志父子第二部叫什么| 爱上特种兵电视剧免费观看完整版 | 林青霞离婚| 柚柚| 杨硕| 诡娃| 神仙我才不稀罕短剧在线观看| 三年片电影| 起底员工上满8小时被扣工资的公司| 黑帮大佬和我的第365天| 好看的拉片| 诺曼瑞杜斯| 褚阳| 诺埃尔| 幻想电影在线播放完整版| 八角笼中电影| 黑手党电影| 飞龙猛将演员表| 怎么剪福字简单方法视频| 叶子楣地下裁决| 保镖电影大全免费|