-
Notifications
You must be signed in to change notification settings - Fork 0
/
flow3.m
42 lines (31 loc) · 1.01 KB
/
flow3.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
%Section 3.1.6
close all; clear all;
% Set bounds
x1min = 0; x1max = 20; x2min = 0; x2max = 5;
%Set step size
x1step = 0.5; x2step = 0.5;
%Create plot
[x1, x2] = meshgrid(x1min:x1step:x1max, x2min:x2step:x2max);
%Set values for constants
a = 1.5; b = 1.1; c = 2.5; d = 1.4;
%Lotka-Volterra System
dx1 = -a.*x1 + b.*x1.*x2;
dx2 = c.*x2 - d.*x1.*x2;
%Normalize vectors
dx1 = dx1./sqrt(dx1.^2 + dx2.^2);
dx2 = dx2./sqrt(dx1.^2 + dx2.^2);
%Plot component curves
[t, v,] = ode45(@sys1, [0,20],[0.5,1.0]);
plot(t,v(:,1),'Linewidth',2);
hold on
[t, v,] = ode45(@sys1, [0,20],[0.5,1.0]);
plot(t,v(:,2),'Linewidth',2);
hold on
legend('x1 Predators','x2 Prey')
%Specify the plotting axes
axis([x1min x1max x2min x2max])
% Label the axes
xlabel('Time (days)','Interpreter','latex')
ylabel('Population (dozens of animals)','Interpreter','latex')
title('Component Curves for Lotka-Volterra System','Fontsize',18,'Interpreter','latex')
grid on