I was wondering if someone might be able to help me solve the Lotka-Volterra equations using MatLab. My code doesn't seem to be working. I do the following:
Step 1 -
I created a file entitled pred_prey_odes.m containing the following code:
% the purpose of this program is to model a predator prey relationship
% I will be using the Lotka-Volterra equations
% Program consists of the following differential equations:
% dY1/dt = a * Y1 - c * Y1 * Y2
% dY2/dt = b * Y2 - d * Y1 * Y2
function dy = pred_prey_odes(t, y)
% function that is to be integrated
%select constants
a = 1;
b = 2;
c = 3;
d = 4;
%set up differential equations
dy = zeros(2,1);
dy(1) = a * y(1) - c * y(1) * y(2);
dy(2) = b * y(2) - d * y(1) * y(2);
I saved the file and made sure it was in the current directory before typing the following code into the command window:
clc
tspan = [0, 20];
y0 = [10; 10];
ode = @(t, y) pred_prey_odes(t, y);
[t, y] = ode45(ode, tspan, y0);
plot (t,y)
However, no plot pops up. In fact, nothing happens in matlab and I can't even clear the command window. If I type clc nothing happens...
Any help would be appreciated!
Thanks!
-Sneha Inguva