Project 14: Calculate Standard Deviation

Intro Problem: Suppose we asked all 10 of your classmates how much they spent on their last haircut and obtained the following values:

5, 0, 50, 70, 100, 10, 30, 40, 140, 25


We know that the average (mean) haircut cost is $47 but how much do students typically deviate from this amount?  For this question, we are interested in how "spread" out the dataset is.

There are a few different measures we could use (range, absolute mean deviation, and the standard deviation).  The standard deviation is $42.61 which tells us the typical difference from a classmates' haircut cost to the average of $47.  This shows us that the haircut costs vary widely.


An explanation for the standard deviation is given below.

The standard deviation yields a typical distance for the values in a dataset from the mean value.  The mean is denoted with the symbol x-bar in the formula above.

Project 14: An array called 'dataset' has been initialized.  There is also a working method called getAverage. The getAverage method accepts an array and returns the average.

example: dataset = {1.0,3.0,17.0}.  getAverage(dataset) returns 7.0

x - xbar: 1.0 - 7.0, 3.0 - 7.0, 17.0 - 7.0 = -6.0, -4.0, 10.0

(x- xbar)^2 = 36.0, 16.0, 100.0

variance = (x-xbar)^2/n = 152.0

sd = sqrt(152) = 12.328828 

Task: Appropriately assign the variable 'sd' that corresponds to the population standard deviation of 'dataset'.

**If your code works for 5 test cases in a row, you can enter your e-mail address.

Universal Computational Math Methods:

pow(5,2) returns 25.0

abs(-3.0) returns 3

sqrt(49.0) returns 7.0