Binomial distribution. Write a function
public static double binomial(int n, int k, double p)
to compute the probability of obtaining exactly k heads in n biased coin flips (heads with probability p) using the formula
f(n, k, p) = pk(1−p)n−kn!/(k!(n−k)!)
Hint: To stave off overflow, compute x = ln f(n, k, p) and then return ex. In main(), take n and p from the command line and check that the sum over all values of k between 0 and n is (approximately) 1. Also, compare every value computed with the normal approximation
f(n, k, p) ≈ ϕ(np, np(1−p))
(see EXERCISE 2.2.1).
EXERCISE 2.2.1
Add to Gaussian (PROGRAM 2.1.2) an implementation of the three-argument static method pdf (x, mu, sigma) specified in the API that computes the Gaussian probability density function with a given mean μ and standard deviation σ, based on the formula ϕ(x, μ, σ) = ϕ ((x − μ)/σ)/σ. Also add an implementation of the associated cumulative distribution function cdf (z, mu, sigma), based on the formula Φ(z, μ, σ) = Φ(z − μ) / σ).
Program 2.1.2 Gaussian functions
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.