Project 63: SD of Discrete Random Variable

For the distribution below, there is a 10% chance that X is 5, a 20% chance that X is 10, a 30% chance that X is 15, and a 40% chance that X is 20.  The calculations are shown below that the mean (or the expected value) for X is 15 and the standard deviation is 5.

Project 63: Variables x and pX have been initialized.  There is also a working method called getMean.

x is an array that represents the possible values for x ([5, 10, 15, 20] in the example above).

pX is an array that represents the probability of the corresponding value of x ([.1, .2, .3, .4] in the example above).

getMean(x, pX)  returns the mean of the discrete random variable where x are the possible values and pX is the probability of those corresponding values.

Example:

x = [5, 10, 15, 20]

pX = [.1, .2, .3, .4]

getMean(x,pX) returns 15.

Task: Appropriately initialize the value for the variable 'sd' that represents the standard deviation for x.

**If your code works for 5 test cases, 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