Mathcad Solution To XKCD Problem

Quote of the Day

I don't need time – I need a deadline.

— Duke Ellington, describing how he is motivated to get something done. I must admit that I need deadlines for writing, otherwise I would never get anything written.


Figure 1: Velociraptor Vs Prey Problem Statement (Source).

Figure 1: Velociraptor Vs Prey Problem Statement (Source).

XKCD is a great comic strip by Randall Munroe that takes a quirky look at the world of science. Randall recently posted a set of questions for a substitute teacher to pose to a math class that were interesting and attracted the attention of some problem-solving enthusiasts.

I thought I would jump into the fray by solving the problem using Mathcad and also taking my first dive into Python.


While this is a simple problem, it is interesting to see how different people approach it. Here are two other solutions that I recommend you read:

  • Jon Peltier's Excel Solution

    Jon is a world-class Excel expert (e.g. MVP) with a real gift for Excel charting. He attacks the problem using a standard spreadsheet approach and a Visual Basic for Applications (VBA) approach.

  • Rhett Allain's Python Solution

    Rhett wrote a Python-based solution that I used as the basis for my first Python program. I modified his routine to use trapezoidal integration instead of Euler, and I implemented a different scheme for the clipping the velocities.


Mathcad Solution

Figure 2 shows how I used Mathcad to solve the substitute teacher problem.

Figure M: Mathcad Solution to XKCD Problem.

Figure 2: Mathcad Solution to XKCD Problem.

Figure 3 shows my graphical view of the solution.

Figure M: Plot of Raptor Versus Prey.

Figure 3: Plot of Raptor Versus Prey.

Python Solution

I have never written a Python program before and this seemed like a great opportunity to learn. When I looked at Rhett's program, it reminded me a simplified form of Java – my usual programming language choice. So I quick ran through the Python course on Code Academy and loaded Python onto my Eclipse install.

Figure 4 shows my Python routine, which gave me the same results as Mathcad. Python seems a lot less wordy than Java – what were the Java folks thinking?

Figure 4: My Python Solution for the Substitute Teacher Problem.

Python Graphic Output

Figure 5 shows the output from my Python program. The results are the same as given by Mathcad.

Figure M: Python Plot of Prey and Velociraptor Position.

Figure 5: Python Plot of Prey and Velociraptor Position.


This problem nicely illustrates how different tools can be used to solve a problem. In my case, I tend to use computer-algebra systems, like Mathcad and Mathematica, to experiment with different approaches to solve a problem. I only commit to software when I need more speed or the ability to handle large scale.

This entry was posted in General Mathematics. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *