We use cookies to enhance your experience on our website. By continuing to use our website, you are agreeing to our use of cookies. You can change your cookie settings at any time. Find out more
Oxford University Press
  OUP Worldwide
Advanced Search
Printer-Friendly View

Companion Website

Boudreau and Swanson: Applied Computational Physics

Chapter 07: Monte Carlo Methods

example code (.tgz)

  • HIST: a simple demonstration of how to generate and visualize a uniform variate in a Qat histogram.
  • THROWAWAY1: demonstrate how to sample a simple probability distribution using the throwaway (or von Neumann rejection) method.
  • THROWAWAY2: demonstrate how to sample a point probability distribution, using the throwaway (or von Neumann rejection) method.
  • DIRECTSAMPLE: demonstrates the direct sampling method, otherwise known as the transformation method. A choice of three examples is made from the command line. These three examples are discussed in the text.
  • BASICMCINTEGRATE: example in section 7.4.2 of the text, where Monte Carlo integration is discussed.
  • MCMC/HYDROGEN, MCMC/HYDROGEN-ANIM, and MCMC/HYDROGEN-PLOT: use Markov chain Monte Carlo to generate a realization of the probability density function of hydrogen orbitals.

    mcmc-hydrogen [NPOINTS=val{def=10000}] [N=val{def=0}] [L=val{def=0}] [M=val{def=0}] [fSigma=val{def=1.0}
    mcmc-hydrogen-anim [NPOINTS=val{def=10000}] [N=val{def=0}] [L=val{def=0}] [M=val{def=0}] [fSigma=val{def=1.0}
    mcmc-hydrogen-plot [NPOINTS=val{def=10000}] [N=val{def=0}] [L=val{def=0}] [M=val{def=0}] [fSigma=val{def=1.0}

    NPOINTS Number of points in the Markov Chain (10000)
    N Principal Quantum Number (1)
    L Angular Momentum Quantum Number (0)
    M Magnetic Quantum Number (0)
    fSigma Under/over scale the proposal distribution

    The animated version ("mcmc-hydrogen-anim") refreshes after 2000 steps. It's fSigma parameter is not ideal for a decent sampling of the distribution, but the purpose of the example is to illustrate burn-in.
  • MCMC/SMOKE: a simulation of smoke particles diffusing throughout a rectangular space.
  • BWDOPPLER: the starting point for an exercise in chapter 7.
  • INTPOW: integrates xN over [0,1] using Monte Carlo integration.
  • INTPULL: monitors the pull distributions from the ensemble of statistically independent evaluations of the integral above.
  • SUMUNIFORM: plots the sum of one, two, three, and four uniform variates.
  • X5: illustrates the transformation method to generate variables according to xN. The exponent is given on the command line.

About this book
Price, bibliographic details, and more information on the book