APS Excellence in Physics Education Award
November 2019

Education Prize Logo
Science SPORE Prize
November 2011

NSF Logo
The Open Source Physics Project is supported by NSF DUE-0442581.

Errata in An Introduction to Computer Simulation Methods

Return to the Curriculum Authoring and Teaching forum
Login to post to this thread

Sign error
Larry Engelhardt
17 Posts

In the right-hand side of equation (9.56) on page 341, the term "u(x + Delta x, t)" appears twice.  One of these should be replaced with "u(x - Delta x, t)".

Missing minus signs on page 329
Larry Engelhardt
17 Posts

On page 329 (equations 9.34 - 9.37) the lower limits of the integrals and the summations are each missing a minus sign.

Error in IdealDemon
Larry Engelhardt
17 Posts

This is not actually an "error", as I initially thought that it was.  Currently the variables systemEnergyAccumulator and demonEnergyAccumulator are being updated every time that a change is proposed, rather than being updated once per MCS.  Unless the number of MCS is large, these two methods of averaging will yield different results.  The code below shows the changes that will result in data only being accumulated once per MCS.

Alternate method for IdealDemon.java:

  public void doOneMCStep() {
    for(int j = 0;j LESSTHAN N;++j) {
      int particleIndex = (int) (Math.random()*N); // choose particle at random
      double dv = (2.0*Math.random()-1.0)*delta;   // random change in velocity
      double trialVelocity = v[particleIndex]+dv;
      double dE = 0.5*(trialVelocity*trialVelocity-v[particleIndex]*v[particleIndex]);
      if(dE LESSTHANOREQUALTO demonEnergy) {
        v[particleIndex] = trialVelocity;
        systemEnergy += dE;
        demonEnergy -= dE;
    systemEnergyAccumulator += systemEnergy;
    demonEnergyAccumulator += demonEnergy;    

Alternate code for IdealDemonApp.java:

    control.println("Mean Ed = "+idealGas.demonEnergyAccumulator/idealGas.mcs);
    control.println("Mean E = "+idealGas.systemEnergyAccumulator/idealGas.mcs);

Post edited February 21, 2009 at 2:53 PM EST.

Current Replies - View all
Re: Error in IdealDemon   (Jan Tobochnik - )
Sign in Problem 8.4
Larry Engelhardt
17 Posts

In the code that is listed in Problem 8.4(a), the line

y[i] = (i - 0.5) *Ly/N;

should contain a + sign rather than a - sign,

y[i] = (i + 0.5) *Ly/N;

otherwise the bottom molecule will begin outside of the box.

PBCs in setRandomPositions()
Larry Engelhardt
17 Posts

In the setRandomPositions() method in the file LJParticles.java, the periodic boundary conditions are not taken into account when determining whether or not two molecules are overlapping, often causing the simulation to get stuck when using these initial conditions.  Listing 8.4 in the CSM texbook correctly incorporates the PBCs in the lines:

double dx = pbcSeparation(state[4*i]-state[4*j], Lx);
double dy = pbcSeparation(state[4*i+2]-state[4*j+2], Ly);

Exercise 8.2
Larry Engelhardt
17 Posts

In part (b) of Exercise 8.2, the line of code that is listed contains extra slashes (\).

The line should read:

return x<0 ? x%L + L:  x%L;

Missing "?" in problem 8.10
Larry Engelhardt
17 Posts

On page 278, the first sentence of problem 8.10(a) ends with a period which should be a question mark.

Typo in subscripts in Eq. 6.66(c)
Larry Engelhardt
17 Posts

In equation 6.66(c) on page 188, the subscripts are incorrect.  In order to correctly represent the reactions, Eq. 6.66(c) should read

dC/dt = k_5*B - k_6*C

rather than

dC/dt = k_4*B - k_5*C

BifurcateApp.java plotting too few data points
Larry Engelhardt
17 Posts

The file BifurcateApp.java (from Ch. 6 of CSM) shows the bifurcation that occurs for the logistic map as a function of the parameter r.  The application receives the number of data points to be plotted (per r value) as input (from the user) through the control window, which is written into the variable "nplot".  However, the application only plots 0.75*nplot data points, because the command i++ appears twice in the loop for dataset 1.  It appears both as the iterator for the for loop,

for(int i = nplot/2+1; i lessthan nplot; i++)

and it appears as the last statement within the body of the for loop,


Post edited December 13, 2008 at 9:31 AM EST.

Post edited December 13, 2008 at 9:33 AM EST.

Error in Lorenz.java
Larry Engelhardt
17 Posts

The file Lorenz.java is meant to simulate the model represented by Eqs. 6.33 (a)-(c) on page 167 of CSM.  However, there is an error in the getRate method.

The line,

rate[2] = (state[0]*state[1]-state[2])*b;

should be modified to read

rate[2] = state[0]*state[1] - b*state[2];

in order to correctly represent Eq. 6.33c.

Axis labels in GraphicalSolutionApp.java in Ch. 6
Larry Engelhardt
17 Posts

The file GraphicalSolutionApp.java (listing 6.3 in the CSM textbook) is used to graphically show how the logistic map is iterated.  The quantity on the horizontal axis should be "x" (the current value of x_n), and the quantity on the vertical axis should be "f(x)" (the next value of x_n).  These axis are mislabeled as "iterations" for the horizontal-axis label and "x" for the vertical-axis label.

Sign error in Ch. 9 dealing with Huygen's wavelets
Larry Engelhardt
17 Posts

In the CSM textbook, there is an error in Eq. 9.62 of on page 347.  Specifically, the "-" sign should be a "+" sign.  This equation reads:

E(r,t) = Re(E)*cos(omega*t) - Im(E)*sin(omega*t)

and it should read:

E(r,t) = Re(E)*cos(omega*t) + Im(E)*sin(omega*t)

In the related code (HuygensApp.java), the calculation includes three minus signs:

E(r,t) = Re(E)*cos(-omega*t) - Im(E)*sin(-omega*t)

which is equivalent to the second equation above.  In other words, E(r,t) can be simplified slightly in HuygensApp.java by writing it without minus signs as:

E(r,t) = Re(E)*cos(omega*t) + Im(E)*sin(omega*t)

OSP Projects:
Open Source Physics - EJS Modeling
Physlet Physics
Physlet Quantum Physics
STP Book