# Homework 5¶

## Due 23.59, Nov/12/2017¶

### Angry Birds: ODE Modeling and Computation¶

This homework is a modified version of a homework originally designed by Daniel Appelo. It concerns the simulation of angry birds. More precisely, we will model and simulate the flocking behavior of birds in a two-dimensional space. This problem is of societal and scientific importance as it could give insight into the dynamics of diseases, magnets, populations, etc.

### I. Modeling¶

The goal of this part is to derive a set of ODEs, as a mathematical model, that describes the flocking behavior of a flock of $$N$$ birds. Let $$B_k(t) = (x_k(t),y_k(t))$$ be the location of the $$k$$-th bird at time $$t$$, where $$k=1, 2, \dotsc, N$$. Of course, $$B_1(t)$$ is the location of the bird leader who does not really care too much about the other birds but is primarily interested in eating some tasty food being handed out by a crazy bird feeder at $$C(t) = (x_c(t),y_c(t))$$. At any instance of time $$B_1(t)$$ is thus trying to reduce its distance to $$C(t)$$ by

$$B'_1(t) = \gamma_1 \, (C(t)-B_1(t)),$$

where $$\gamma_1>0$$ is a positive constant whose magnitude depends on how good the food tastes. The rest of the birds try to stay close to the leader. They are hence governed by

$$B'_k(t) = \gamma_2 \, (B_1(t)-B_k(t)) ,\qquad k = 2,\ldots,N,$$

where $$\gamma_2>0$$ depends on how charismatic the bird leader is.

Another important mechanism is related to the safety of the flock. The birds try to be as close as possible to the middle of the flock (or the flock’s center of mass), denoted by $$\bar{B} (t)= \sum_{k=1}^N B_k (t) / N$$. This will be safer if for instance the flock is attacked by a predator trying to single out a lonely bird to catch. This can be described by a flocking force that holds the birds together:

$$F_{k}^{\text{fl}} (t) = \kappa \, (\bar{B}(t)-B_k(t)),\qquad k = 2,\ldots,N.$$

This flocking force can be added to the right hand side of the ODEs system.

Of course if the birds get too close to each other they cannot maneuver properly so there is also a strong repelling force. If the $$k$$-th bird $$B_k$$ is repelled by its $$L$$ closest neighbors we can add to the right hand sides

$$F_k^{\text{rep}}(t) = \sum_{l=1}^L \rho \, \frac{(B_k(t)-B_l(t))}{(B_k(t)-B_l(t))^2+\delta},\qquad k = 2,\ldots,N,$$

where $$\rho$$ is a constant steering the magnitude of the force.

There may also be other forces, such as predator avoidance, obstacle aviodance forces, grouping forces, etc, that govern the flocking behavior. In this assignment you wil experiment with a few variants of the mathematical model.

### II. Computation¶

You will compute the derived system of ODEs, with some randomly chosen initial locations for the birds $$B_k(0) = (x_k(0), y_k(0)), \ \ k=1, 2, \dotsc, N$$, using the classic fourth order Runge-Kutta method (RK4). You are free to write your code either in Matlab or Fortran or both.

Assignments:

1. Write down the system of ODEs including all force terms. Explain in words what the meaning of the equations is (think about avoidance and engagement). Describe, for example, what does it mean when $$x_c > x_1$$?
2. Implement RK4 and experiment with different parameters and different number of birds (for example $$N=10, 100, 1000$$, etc.). Can you explain how different parameters impact the behaviour of the flock? Try with some different examples of $$C(t)$$ including $$C(t) = (0,0)$$ and $$C(t) = (\sin(\alpha \, t),\cos(\alpha \, t))$$.
3. How does the flock diameter (what is a reasonable definition?) change over time and for different scenarios?
4. Add a smelly bird that wants to be at the center but is strongly repellant to other birds.
5. (Optional with 20 bonus points) Can you add a predator to the system by adding a predator avoidance force $$F_k^{\text{pr}}(t)$$ to the right hand sides? You can either place the predator at a fixed point in the way of the flock or choose a dynamic (time-dependent) location for the predator.
6. Write up a nice report with your findings. Add some movies of Angry birds to your repository.

Below is a movie that I created using a simple model of flocking birds.