Written by Dave Martin
• 7/23/2018

The oh-so-popular Shark Week starts on July 22nd on the Discovery Channel. In honor of that event, let’s take a look at how we can apply math to the behavior of sharks.

It turns out that the motion of sharks in water can be described by two different models from math and physics, both of which are connected to random numbers: Brownian motion and Levy flights.

When food is abundant in their environments, sharks follow Brownian motion when searching for prey. When particles that don’t dissolve in a fluid are impacted by particles in that fluid, their motion is chaotic and random. Examples include the way that food coloring disperses in water or the way a car’s exhaust expands through the air. When sharks move in this way, they make a lot of quick turns and changes in direction.

When food is scarce, sharks abandon Brownian motion for Levy flights. This type of motion is characterized by mostly short, random turns and movements – like Brownian motion – interspersed with occasional long legs of motion along a straight line.

Levy flights are considered to be the optimal method for searching in an environment, say if you were looking for a lost hiker in the woods or an escaped prisoner.

## Simulate Brownian Motion with PTC Mathcad

Let’s simulate this motion in three dimensions. We’ll take advantage of three main capabilities: (1) built-in functions including those for random numbers; (2) programming; and (3) graphing capability.

First, take a look at a program that simulates Brownian motion:

This program generates random numbers for distance f, azimuthal angle θ, and polar angle φ. Using trigonometry, we convert these values into distances in the x, y, and z directions, and add those values to the previous location. These new coordinates are added as entries in a matrix.

Here’s an example of a plot in two dimensions, of the x- and y- coordinates:

But the ocean has depth as well. In PTC Mathcad, we can generate 3D plots of the matrix:

The results change every time we hit the Calculate button, since the random numbers are regenerated. Here is an example of another random solution:

I captured a bunch of images and strung them together into a GIF:

## Calculating Levy Walk with PTC Mathcad

Now let’s examine how the shark’s motion changes when disaster strikes and food is much harder to find. The shark searches with a bunch of random turns and motions, but to maximize the search volume and chance of coming across prey, it randomly travels long legs to wind up in a completely different location.

So how do we get those additional random long legs? Based on some help I found on the Mathematics Stack Exchange , we can accomplish this by using an inverse cumulative distribution function.

Here is an example of a random solution for the shark’s Levy walk:

Just as before, by hitting the Calculate button, we can generate a number of solutions to see how different the motion can be under the Levy walk compared to Brownian motion:

What do we learn from a shark’s natural motion to help us survive? Since the shark makes a lot of short twists and turns, your best bet is to travel in a straight line, as fast as you can, out of the shark’s habitat. Better yet, follow this advice to maximize your chances of avoiding a shark attack altogether.

Enjoy Shark Week!