x, y = random_walk_2d(1000) plt.plot(x, y) plt.title("Mark Newman's Random Walk Example") plt.show() Q: Is the Mark Newman computational physics PDF legal? A: Yes—Prof. Newman explicitly states on his site: “The PDF is freely available for personal use or for instructors to assign in classes.”
Looking for the Computational Physics by Mark Newman PDF? Find the official free download link from the author’s website, plus a chapter summary, code examples (Python), and legal alternatives.
import numpy as np import matplotlib.pyplot as plt def random_walk_2d(steps): x, y = np.zeros(steps), np.zeros(steps) for i in range(1, steps): theta = np.random.uniform(0, 2*np.pi) x[i] = x[i-1] + np.cos(theta) y[i] = y[i-1] + np.sin(theta) return x, y
A: Python 3 (with NumPy 1.7+). The code works today with minor tweaks (e.g., print functions).