Given an array of elements. We need to find the Standard Deviation of the elements of the array in PHP.
Input : array(2, 3, 5, 6, 7) Output : 1.5620499351813 Input : array(1, 2, 3, 4, 5) Output : 1
The following problem can be solved using the PHP inbuilt functions. The inbuilt functions used to solve the above problem are as such:
- array_sum(): The function returns the sum of all the elements of an array.
- count(): This function gives the number of elements currently present in the given array.
- sqrt(): The function returns the square root of the given number.
To calculate the standard deviation, we have to first calculate the variance. The variance can be calculated as the sum of squares of differences between all numbers and means. Finally to get the standard deviation we will use the formula, √(variance/no_of_elements).
Below is the implementation in PHP to calculate the standard deviation:
- D3.js | d3.deviation() function
- PHP | Sort array of strings in natural and standard orders
- PHP program to find missing element(s) from an array
- PHP program to find the maximum and the minimum in array
- PHP program to find the length of the last word in string
- Program to find the number of days between two dates in PHP
- PHP | Program to delete an element from array using unset() function
- Program to remove empty array elements in PHP
- Program to Insert new item in array on any position in PHP
- PHP program to add item at the beginning of associative array
- What is the difference between array_merge and array + array in PHP?
- PHP 5 vs PHP 7
- PHP | Get PHP configuration information using phpinfo()
- PHP | php.ini File Configuration
- How to import config.php file in a PHP script ?
- Java Program to Check Array Bounds while Inputing Elements into the Array
- PHP program to fetch data from localhost server database using XAMPP
- PHP program to change date format
- PHP Program to count Page Views
- PHP program to print an arithmetic progression series using inbuilt functions
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.