Home > Articles

  • Print
  • + Share This
This chapter is from the book

Exercises

  • 2.4.1 Write a program that takes a command-line argument n and creates an n-by-n boolean matrix with the element in row i and column j set to true if i and j are relatively prime, then shows the matrix on the standard drawing (see EXERCISE 1.4.16). Then, write a similar program to draw the Hadamard matrix of order n (see EXERCISE 1.4.29). Finally, write a program to draw the boolean matrix such that the element in row n and column j is set to true if the coefficient of xj in (1 + x)i (binomial coefficient) is odd (see EXERCISE 1.4.41). You may be surprised at the pattern formed by the third example.

  • 2.4.2 Implement a print() method for Percolation that prints 1 for blocked sites, 0 for open sites, and * for full sites.

  • 2.4.3 Give the recursive calls for flow() in PROGRAM 2.4.5 given the following input:

    3 3
    1 0 1
    0 0 0
    1 1 0
  • 2.4.4 Write a client of Percolation like PercolationVisualizer that does a series of experiments for a value of n taken from the command line where the site vacancy probability p increases from 0 to 1 by a given increment (also taken from the command line).

  • 2.4.5 Describe the order in which the sites are marked when Percolation is used on a system with no blocked sites. Which is the last site marked? What is the depth of the recursion?

  • 2.4.6 Experiment with using PercolationPlot to plot various mathematical functions (by replacing the call PercolationProbability.estimate() with a different expression that evaluates a mathematical function). Try the function f(x) = sin x + cos 10x to see how the plot adapts to an oscillating curve, and come up with interesting plots for three or four functions of your own choosing.

  • 2.4.7 Modify Percolation to animate the flow computation, showing the sites filling one by one. Check your answer to the previous exercise.

  • 2.4.8 Modify Percolation to compute that maximum depth of the recursion used in the flow calculation. Plot the expected value of that quantity as a function of the site vacancy probability p. How does your answer change if the order of the recursive calls is reversed?

  • 2.4.9 Modify PercolationProbability to produce output like that produced by Bernoulli (PROGRAM 2.2.6). Extra credit: Use your program to validate the hypothesis that the data obeys a Gaussian distribution.

  • 2.4.10 Create a program PercolationDirected that tests for directed percolation (by leaving off the last recursive call in the recursive flow() method in PROGRAM 2.4.5, as described in the text), then use PercolationPlot to draw a plot of the directed percolation probability as a function of the site vacancy probability p.

  • 2.4.11 Write a client of Percolation and PercolationDirected that takes a site vacancy probability p from the command line and prints an estimate of the probability that a system percolates but does not percolate down. Use enough experiments to get an estimate that is accurate to three decimal places.

  • + Share This
  • 🔖 Save To Your Account