Computational physics 16.2: The rope as two arrays
Keep the rope in two NumPy arrays: y, the heights, and vy, the speeds. Lift a hump with a slice, work out every piece's acceleration with the slices of unit 14, and step the whole rope with threeโฆ
153 posts match
Keep the rope in two NumPy arrays: y, the heights, and vy, the speeds. Lift a hump with a slice, work out every piece's acceleration with the slices of unit 14, and step the whole rope with threeโฆ
Lift a hump and let go: it splits into two humps half as high that run apart along the rope. Draw them at four moments, and time one of them to check that the simulation's waves travel at the speedโฆ
Tie the rope to posts and flick one end: a hump runs along the rope, and comes back from the far post upside down. Flick both ends at once, and two humps meet, add up and pass through eachโฆ
Make the time step a little bigger and the rope zig-zags and blows up. The Courant number C = vยทdt/dx, the pieces a wave crosses in one step, says why: the simulation only passes news on one pieceโฆ
Start the rope in the shapes of physics lesson 10.4, sines with whole loops, and they swing in place, with nodes that never move. Time them with a stopwatch, check f = nv/(2L), and find the note ofโฆ
Mixed questions from unit 16: the pull of the neighbours, a piece stepped with EulerโCromer, the rope as two arrays, a pulse timed, fixed ends and flicked ends, the Courant condition, and standingโฆ
Random numbers spread evenly between 0 and 1 with rng.random(N), and between a and b with rng.uniform(a, b, N). Why the seed makes every run the same, and probability as the fraction of tries inโฆ
Throw random points into a square with a quarter circle in it. The share that lands inside is ฯ/4, so four times that share estimates ฯ: close, never exact, and a little different for every seed. ฯโฆ
Put a box around a graph and throw random points into the box. The share under the curve, times the box's area, is the area under the graph: the distance gone, for a car and for lesson 11.3's tramโฆ
An average over random tries: the tram's distance from its average speed at random times, then stones dropped from random heights, their average fall time, and the share of them that take longerโฆ
Estimate ฯ 200 times and look at how much the estimates scatter: s รท โN, the rule of lesson 9.3. Four times the points only halves the error. Set against the rules of units 5 and 11, Monte Carlo isโฆ
One run is enough to say how sure it is: estimate ยฑ s/โN, from the tries themselves. How often the truth lies inside the error bar, how many points a target needs, and the tram's distance with itsโฆ
Mixed questions from unit 17: random numbers with a seed, probability as a fraction of tries, estimating ฯ and areas, averages over random starts, the 1/โN rule and error bars. New numbers on everyโฆ
A walker leaves a lamp post and takes each step left or right at random. Simulate his walk with rng.choice([-1, 1]), one step at a time and then all at once, and draw his whole path withโฆ
One walk tells one story; a crowd tells what is typical. Make a table of random steps with size=(walkers, steps), one row per walker, and add each row with np.sum(steps, axis=1) to find where allโฆ
Square the ends so the two sides can't cancel: the mean of xยฒ comes out at N, the number of steps. Its square root, the typical distance, is โN: four times the steps, only twice as far. See it atโฆ
A molecule in still water is knocked about at random: a random walk with a jump dx every dt. After a time t it is typically dxยทโ(t/dt) away, so it spreads as โt, and twice as far takes four times asโฆ
Where is the crowd? Count the walkers at each position with np.sum(x == k) and draw the counts: a histogram, bell-shaped, with gaps at every odd position. A walker who sometimes stays put fills theโฆ
On average, a quarter of the lazy walkers at a spot step to each side and half stay: that is unit 14's diffusion step with r = ยผ. Run it on an array and it draws the crowd's histogram; its spread isโฆ
Mixed questions from unit 18: one random walk and its path, a crowd of walkers in one table, the spread โN, a molecule's walk in time and space, counting walkers, and the diffusion step the crowdโฆ
Three hundred molecules in a box, kept in two arrays and moved all at once with pos = pos + velยทdt. Walls that bounce them back, and a gas that spreads out to fill its box and stays spread. A litreโฆ
Work out the average kinetic energy of the molecules, and from it their temperature with (3/2)kT. See that the temperature of the gas in the box stays put, and make a gas at the temperature youโฆ
Every molecule that bounces off a wall gives it a push of 2mv. Add up the pushes on the walls, turn them into a pressure, and check the box against the ideal gas equation, pV = NkT. Your programโฆ
What collisions do: pass energy from one particle to another at random. Simulate physics lesson 20.3's packets of energy, handed on again and again, and see that most atoms end up with little energyโฆ