# Lotka-Volterra Visualization

This project was a follow up to my post about the predator-prey model derived by Alfred Lotka and Vito Volterra. I chose to do this for two reasons. First its always easier to understand concepts when you have their meanings visualized and applied to real life. Second, when I took ODE’s phase planes where just lines and numbers on the board. After this project, I wholesomely understood the significance of phase planes, and they’re truly enlightening. I want to share that with everyone!

It’s a very straight forward program. I chose arbitrary values for the constants, my only concern was that the center point was at (2,2). The constants are $a_1 = 2\ \ a_2 = 2\ \ b_1 = 1\ \ b_2 = 1$.

All of the code and documentation is at my github repository.

## Program Layout

I use OpenGL to plot solutions on the phase plane. The solutions are lines of particles that flow under the forces of the vector field from the Lotka-Volterra equations. I used a graph generated from gnuplot as the background. The graph is the vector field from (5,5) with center point at $(\frac{a_2}{b_2},\ \frac{a_1}{b_1})$.

Then I use OpenCV to plot both populations against time. The sinusoidal graphs are just a sequence of lines drawn from pixel to pixel along the graph. Each pixel’s succeeding location is updated by the Lotka-Volterra equations as well. They’re plotted on top of the graph below, it as well was generated from gnuplot.

## See it in Action

If you’re curious about what it looks like in action, I made a video about it in my math math modeling section.

## To Do List

I learned OpenGL for this program, so it’s a little buggy and certainly not very clean.

There are a bunch of constants I had to experimentally derive to scale the mouse clicks to the appropriate dimensions for both windows. I’m sure there is a better way to go about doing it.

This could have eaily been written only in OpenCV, but then I wouldn’t have had the excuse to learn OpenGL! =]

## Special Thanks

Thanks to my friend Ian Johnson for all of his help.
Also thanks to David Kopriva for teaching me about math models!

This entry was posted in Lotka-Volterra Visualizer. Bookmark the permalink.

### 4 Responses to Lotka-Volterra Visualization

1. Michael Norrington says:

Hey great visualizer Nathan. Really useful. How difficult would it be for you to modify for the Competitive Lotka-Volterra equations? http://en.wikipedia.org/wiki/Competitive_Lotka%E2%80%93Volterra_equations

Thanks!

2. Nathan Crock says:

Thanks Michael! Editting the equations is a piece of cake. Lines 325-327 in main.cpp take care of updating the particle’s position. You could switch out the lotka volterra equations for any vector field! It looks like the competitive LV equations are still first order. Just change alpha and beta to the per capita growth rate, and the carrying capacity and then edit the equations on lines 326-327. You may also have to change the dimensions of openGL’s bounding box to see the solution, and I can’t guarantee convergence using forward Euler as I did. None-the-less all the ingredients are there, let me know how it works out for ya!

3. Magnus Muneer says:

With Respect,
I have been a Life-Science student throughout my carrier. As expected I am not good in Mathematics. I will be highly thankful if you will send step-by-step explanation of all the mathematical equations (or other relevant study-material) involved in Lotka-Volterra model to my e-mail ID (mislam.esst@gmail.com). Or just simply suggest me some websites & books which will be helpful for me to fully understand this model and the mathematical equations in it.
Thank You.

4. aysha jesin says:

thank you very much for your explanation, i am doing a project work mainly saying about the relation between jacobian matrix and lotka volterra predator prey method, and i had doubt ,when i find the eigenvalues of system ,i got purely imaginary value..what did it mean , how can i conclude project