FD1D_PREDATOR_PREY
Predator Prey Simulation
in 1D


FD1D_PREDATOR_PREY is a MATLAB program which uses finite difference methods for the dynamics of predator-prey interactions in 1 spatial dimension and time, by Marcus Garvey.

The MATLAB code is mostly self explanatory, with the names of variables and parameters corresponding to the symbols used in the finite difference methods described in the paper.

The code employs the sparse matrix facilities of MATLAB when solving the linear systems, which provides advantages in both matrix storage and computation time. The code is vectorized to minimize the number of "for-loops" and conditional "if-then-else" statements, which again helps speed up the computations.

The linear systems are solved using MATLAB's built in function lu.m. We remark that a pure C or FORTRAN code is likely to be faster than our codes, but with the disadvantage of much greater complexity and length.

The user is prompted for all the necessary parameters, time and space-steps, and initial data. Due to a limitation in MATLAB, vector indices cannot be equal to zero; thus the nodal indices 0,...,J are shifted up one unit to give 1,...,(J+1) so xi=(i-1)*h + a.

The program is structured as follows:

The initial data functions are entered by the user as a string, which can take several different formats. Functions are evaluated on an element by element basis, where x=(x1,...,xJ+1) is a vector of grid points, and so a "." must precede each arithmetic operation between vectors. The exception to this rule is when applying MATLAB's intrinsic functions where there is no ambiguity. Some arbitrary examples with an acceptable format include the following:

        >> Enter initial prey function u0(x)  0.2*exp(-(x-100).^2)
        >> Enter initial predator function v0(x)  0.4*x./(1+x)
      
or,
        >> Enter initial prey function u0(x)  0.3+(x-1200).*(x-2800)
        >> Enter initial predator function v0(x)  0.4
      
This last example shows that for a constant solution vector we need only enter a single number. It is also possible to enter functions that are piecewise defined by utilizing MATLAB's logical operators &, ('AND'), |, ('OR'), and ~ (`NOT'), applied to matrices. For example, on a domain Omega=[0,200], to choose an initial prey density that is equal to 0.4 for 90<=xi<=110, and equal to 0.1 otherwise, the user inputs:
        >> Enter initial prey function u0(x)  0.4*((x>90)&(x<110))+0.1*((x<=90)|(x>=110))
      

Languages:

FD1D_PREDATOR_PREY is available in a FORTRAN77 version and a FORTRAN90 version and a MATLAB version.

Related Data and Programs:

FD_PREDATOR_PREY, a MATLAB program which solves a pair of predator prey ODE's using a finite difference approximation.

FD1D_ADVECTION_FTCS, a MATLAB program which applies the finite difference method to solve the time-dependent advection equation ut = - c * ux in one spatial dimension, with a constant velocity, using the FTCS method, forward time difference, centered space difference.

FD1D_BURGERS_LAX, a MATLAB program which applies the finite difference method and the Lax-Wendroff method to solve the non-viscous time-dependent Burgers equation in one spatial dimension.

FD1D_BURGERS_LEAP, a MATLAB program which applies the finite difference method and the leapfrog approach to solve the non-viscous time-dependent Burgers equation in one spatial dimension.

FD1D_HEAT_EXPLICIT, a MATLAB program which uses the finite difference method and explicit time stepping to solve the time dependent heat equation in 1D.

FD1D_HEAT_IMPLICIT, a MATLAB program which uses the finite difference method and implicit time stepping to solve the time dependent heat equation in 1D.

FD1D_HEAT_STEADY, a MATLAB program which uses the finite difference method to solve the steady (time independent) heat equation in 1D.

FD1D_PREDATOR_PREY_PLOT, a MATLAB program which displays the solution components computed by FD1D.

FD1D_WAVE, a MATLAB program which applies the finite difference method to solve the time-dependent wave equation in one spatial dimension.

FD2D_PREDATOR_PREY, a MATLAB program which implements a finite difference algorithm for a predator-prey system with spatial variation in 2D.

ODE_PREDATOR_PREY, a MATLAB program which solves a pair of predator prey differential equations using MATLAB's ODE23 solver.

Author:

Marcus Garvie

Reference:

  1. Marcus Garvie,
    Finite-Difference Schemes for Reaction-Diffusion Equations Modeling Predator-Prey Interactions in MATLAB,
    Bulletin of Mathematical Biology,
    Volume 69, Number 3, 2007, pages 931-956.

Source Code:

You can go up one level to the MATLAB source codes.


Last revised on 27 February 2009.