Sharing a bicycle (part 5)

Over the past four posts, I developed a simulation of a bicycle sharing problem that appeared in Parade Magazine’s Ask Marilyn column a few years ago. For what I hope will be the final post in this series, I’m going to derive some analytical results.

First of all, the graphs of completion time vs. distance ahead showed that in both the simple case (rA = rB and wA = wB) and the general case with all velocities different, there was a distinct minimum completion time. In order to determine that time, begin by defining the following quantities:

s_{wA} = total distance A walks
s_{rA} = total distance A rides the bicycle
s_{wB} = total distance B walks
s_{rB} = total distance B rides the bicycle

and as before,

wA = A’s walking speed
wB = B’s walking speed
rA = A’s speed on the bicycle
rB = B’s speed on the bicycle

Continue reading “Sharing a bicycle (part 5)”

Sharing a bicycle (part 4)

The function tfinal that I developed for part 3 returns the time for the two friends to complete a journey as a function of six variables: the total distance (s), the distance ahead of the other friend that the rider leaves the bicycle (h), and the walking and riding speeds of each friend (wA,rA,wB, and rB respectively). The graph of completion time vs. distance ahead is so strange-looking that I decided I wanted to see what the whole process looked like for given values of wA, rA, wB, rB, s, and h. That meant writing a function to return a data frame containing the elapsed time and the position of each friend and the bicycle at the end of each event.

Continue reading “Sharing a bicycle (part 4)”

Sharing a bicycle (part 3)

Having derived the equations of motion, it’s a simple matter to translate the math into R code. As we’ll see, the difficult part is understanding the results. The code is below; the most important part is the function tfinal, which implements the four steps as described in previous posts. There are a lot of if statements, and if it weren’t for the return statement I’m not sure how I would have worked this out. This is one case where I really felt the need for a goto statement.

Continue reading “Sharing a bicycle (part 3)”

Sharing a bicycle (part 2)

The last post described a problem in which two friends share a bicycle to go from one friend’s house to the other’s. In this post, I’ll describe my analysis of the problem. Then in the next post I’ll turn this analysis into R code and present some graphics to describe the results.

Recall that there are four basic steps to this problem:

  1. A rides the bike and B walks, until A is a distance h ahead of B, at which time A dismounts and leaves the bike on the sidewalk.
  2. A and B walk until B comes to the bike, at which time B picks it up.
  3. B rides the bike and A walks, until B is a distance h ahead of A, at which time B dismounts and leaves the bike on the sidewalk.
  4. A and B walk until A gets to the bike, at which time A picks it up.

Continue reading “Sharing a bicycle (part 2)”

Sharing a bicycle (part 1)

The following question appeared in Parade Magazine’s Ask Marilyn column for Sunday, May 2, 2010:

A friend and I once went from his house to mine with one bicycle. I started walking and he rode the bike. When he got a couple of blocks ahead, he left the bike on the sidewalk and started walking. When I got to the bike, I started riding, passing him, and then left the bike a couple of blocks ahead. When he got to the bike, he started riding. We did this the whole way.

At least one of us was always walking. At times, one was riding; at other times, we were both walking. I’m sure this was faster than if we had no bike. But some people insist that it was no faster because somebody was always walking. Who’s right?

Marilyn’s answer was: “The reader is right. It’s true that someone was always walking. But neither friend walked the whole distance. Both biked part of the way. This increased their average speed, so they saved time.”

As with the Monty Hall problem, several readers wrote in to disagree with her response, insisting that since someone was always walking, the journey could be no faster than if both had walked the entire distance. What do you think?

The problem statement is somewhat ambiguous, but it seems that what happens is the following (assuming A rides the bike first):

  1. A rides the bike and B walks, until A is a distance h ahead of B, at which time A dismounts and leaves the bike on the sidewalk.
  2. A and B walk until B comes to the bike, at which time B picks it up.
  3. B rides the bike and A walks, until B is a distance h ahead of A, at which time B dismounts and leaves the bike on the sidewalk.
  4. A and B walk until A gets to the bike, at which time A picks it up.

These four steps repeat in sequence until both friends get to the other house.

In his book Number-Crunching: Taming Unruly Computational Problems from Mathematical Physics to Science Fiction, Paul Nahin presents a discrete-time-step solution for the case where both friends share the same walking speed and the same — but higher — bike-riding speed. Over the next couple of posts I’m going to develop an event-driven simulation to determine the travel time in the more general case where all four speeds are different. By event-driven, I mean that instead of discretizing time, I’ll model each of the above four steps as discrete events; the length of the time step will vary.

Stay tuned for the program.

Berkeley Earth vs. NOAA/NCDC

In honor of Earth Day I’m continuing my analysis of temperature data for the United States. We’ve already looked at the state-level data produced by Berkeley Earth, and used it to develop a map of the rise in annual mean temperature (AMT) for the lower 48 US states over the past century. NOAA/NCDC also provides time series of monthly mean temperatures for the individual US States (the data are available near the bottom of this page in the file climdiv-tmpcst-v1.0.0-20170404). We can use it to produce a similar map of the AMT rise for each state and compare it with a map developed using the Berkeley data.

To estimate statewide rise in AMT over a given time interval, I use loess to generate a smooth curve through the annual temperatures, then take the difference between the smoothed temperatures at the endpoints of the interval.

Continue reading “Berkeley Earth vs. NOAA/NCDC”

Climate Change by US Climate Division

The previous post presented a choropleth map of the rise in annual mean temperature for each of the lower 48 US States over the period 1901-2012 based on data produced by Berkeley Earth. The map shows that over the period in question, the northern states experienced the largest rise in mean temperature. However, since statewide averages tend to smooth out changes that occur over smaller areas, my next objective was to develop a similar map for all 3,108 counties in the lower 48 States. Though such data likely exists (and could be generated using the Berkeley Earth software), I was unable to find it online. I did however find another interesting dataset with temperatures on a smaller scale: the NOAA/NCDC Climate Division data.

Continue reading “Climate Change by US Climate Division”