Project 32: Geometcdf
Suppose you have a 20% chance of winning a particular game of chance. You plan to play until you win. The distribution of games you will play is defined by the geometric distribution with p = .2.
The tree diagram for the first several possibilities is shown below.
If X = the number of games played
P(X = 1) = .2
P(X = 2) = .8*.2 = .16
P(X = 3) = .8*.8*.2 = .128
P(X = 4) = .8^3*.2 = .1024
X can possibly be any number from 1 to infinity but the probabilities continually decrease. The sum of all the probabilities for X still must equal 1.
If we wanted the probability that X is between 2 and 4 inclusively, we would add the probabilities:
.16 + .128 + .1024
to get .3904
Project 32: The variables 'p', 'low', 'high' have been initialized. There is also a working method called geometpdf.
p represents the probability of success on any trial (.2 in the example shown above)
low represents the lower bound for X (inclusively)
high represents the upper bound for X (inclusively)
geometpdf(p, k) returns the probability of getting the first success on trial k (when every trial has 'p' probability of success)
example: geometpdf(.2, 3) = .1024
Task: Appropriately initialize the value of 'geometcdf' that represents the probability that the number of trials needed is between low and high inclusively.
Example: if p = .2, low = 2, and high = 4, then geometcdf should be .3904
**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