Home  >  Article  >  Backend Development  >  Function code for finding polynomial derivatives in PHP

Function code for finding polynomial derivatives in PHP

不言
不言Original
2018-06-21 11:22:552927browse

The function code for finding polynomial derivatives written in PHP, friends who need it can refer to it

=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

The above is the entire content of this article. I hope it will be helpful to everyone’s study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

3 ways to generate random numbers in php

How to use php to dynamically generate all rights reserved Information method

The above is the detailed content of Function code for finding polynomial derivatives in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn