Question: Modify Bernoulli (Program 2.2.6) to animate the bar graph, replotting it after each experiment, so that you can watch it converge to the Gaussian distribution.

Modify Bernoulli (Program 2.2.6) to animate the bar graph, replotting it after each experiment, so that you can watch it converge to the Gaussian distribution. Then add a command-line argument and an overloaded binomia () implementation to allow you to specify the probability \(p\) that a biased coin comes up heads, and run experiments to get a feeling for the distribution corresponding to a biased coin. Be sure to try values of \(p\) that are close to 0 and close to 1 .

Program 2.2.6 Bernoulli trials public class Bernoulli { public static int binomial

Program 2.2.6 Bernoulli trials public class Bernoulli { public static int binomial (int n) { // Simulate flipping a coin n times; return # heads. } int heads 0; for (int i = 0; i < n; i++) if (StdRandom.bernoulli (0.5)) heads++; return heads; public static void main(String[] args) { // Perform Bernoulli trials, plot results and model. int n = Integer.parseInt(args[0]); int trials = Integer.parseInt(args[1]); n number of flips per trial int[] freq = new int[n+1]; trials number of trials for (int t = 0; t < trials; t++) freq [binomial (n)]++; freq[] experimental results double[] norm = new double[n+1]; norm[] normalized results for (int i = 0; i

Step by Step Solution

3.38 Rating (154 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Algorithm Design Questions!