%matplotlib inline
from pylab import *
x = linspace(0, 10)
plot(x, sin(x))
[<matplotlib.lines.Line2D at 0x1067a35c0>]
Let's create an array of 100 runners. Each runner is characterized by his speed, which we draw in the interval from 1 to 20 (km per hour).
runners = random_integers(1, 20, size=(100))
runners.sort()
Let's plot this distribution of speeds:
bar(range(runners.size), runners)
<Container object of 100 artists>
Each runner propagates at his running speed. So while everyone starts at the same position, soon the faster runners will overtake the slower runners. This can be illustrated by the following figure:
def propagate(runners, t):
distance = runners * t
return distance
distance = zeros_like(runners, dtype=float32)
total_time = 0
for ind, t in enumerate([0.1, 0.1, 0.2, 0.2]):
distance += propagate(runners, t)
total_time += t
subplot(2, 2, ind + 1)
title('time=%.2f' % total_time)
bar(range(runners.size), distance)
ylim(0, 12)
tight_layout()
What does this look like if we let runners start from random points?
distance = (rand(runners.size) - 0.5) * 6
total_time = 0
for ind, t in enumerate([0.1, 0.1, 0.2, 0.2]):
distance += propagate(runners, t)
total_time += t
subplot(2, 2, ind + 1)
title('time=%.2f' % total_time)
bar(range(runners.size), distance)
ylim(-3, 14)
tight_layout()