Home > Backend Development > PHP Tutorial > Detailed explanation of PHP's method of calculating the stability of student scores

Detailed explanation of PHP's method of calculating the stability of student scores

*文
Release: 2023-03-19 07:52:01
Original
2294 people have browsed it

This article mainly introduces the stability operation of PHP to calculate student scores based on variance and standard deviation, and involves related operating skills of PHP mathematical operations. Friends in need can refer to it. I hope to be helpful.

The student side of the project has a personal growth profile module, which requires analyzing the student's performance stability through fluctuation collection based on the student's recent ten test scores. Anyone who has studied mathematics knows that this should be achieved using the variance in mathematics. Since I am a scumbag in mathematics, I had to read the relevant instructions and formulas online. See the picture below

Okay, now that you have the formula, it will be easy to do. Next It's just a formula.

$arr1 = array(50, 100, 100, 60, 50);
$arr2 = array(73, 70, 75, 72, 70);
function variance($arr) {
  $length = count($arr);
  if ($length == 0) {
    return array(0,0);
  }
  $average = array_sum($arr)/$length;
  $count = 0;
  foreach ($arr as $v) {
    $count += pow($average-$v, 2);
  }
  $variance = $count/$length;
  return array('variance' => $variance, 'square' => sqrt($variance), 'average' => $average);
}
print_r(variance($arr1));
print_r(variance($arr2));
Copy after login

The above code prints

Array
(
  [variance] => 536
  [square] => 23.15167380558
  [average] => 72
)
Array
(
  [variance] => 3.6
  [square] => 1.897366596101
  [average] => 72
)
Copy after login

By looking at the data, we found that although the average values ​​​​of the two arrays are the same, array 1 fluctuates greatly and the results are unstable, while array 2 fluctuates less and the results are lower than the array 1 stable.

Related recommendations:

Detailed explanation of how PHP displays hexadecimal image data to the web page

Detailed explanation of how PHP prevents Thunder downloads

Detailed explanation of how PHP implements Sudoku solving

The above is the detailed content of Detailed explanation of PHP's method of calculating the stability of student scores. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template