Problem

Binomial distribution. Write a functionpublic static double binomial(int n, int k, double...

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!(nk)!)

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

Step-by-Step Solution

Request Professional Solution

Request Solution!

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.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 2.1