How do I overlay multiple logistic population curves on a single plot?

2 views (last 30 days)
Firstly here is the code I have made to plot a logistic population curve:
% Run logistic dynamics for N generations and plot result
R= 1.6; % goodness/growth parameter
R2 = 0.8
R3 = 9
R4 = 1
n=25; % number of generations
x=[]; % initialise empty list of population values
x(1) = 0.001; % initial population
for t = 1:n-1
x(t+1) = R*x(t)*(1-x(t)); % logistic dynamics
end
figure(1); clf
plot(x,'b');hold on;
plot(x,'go');hold off;
axis([1 n 0 0.45]);
title('Example of Logistic Population Dynamics')
xlabel('Generation number');
ylabel('Population (fraction of max)');
grid on;
Now, i want to vary some factors to see what effect they have on population growth. However, I do not want them on separate plots so could someone explain to me how i can edit my code so i can have multiple logistic population curves on a single plot?
Kind regards and many thanks

Accepted Answer

Star Strider
Star Strider on 25 Apr 2015
You may want to change the axis call, but assuming you want to run curves for each value of ‘R’ and plot them on the same plot, this works:
% Run logistic dynamics for N generations and plot result
Rv= [1.6; 0.8; 9; 1]; % goodness/growth parameter
n=25; % number of generations
G = 1:n;
for r = 1:length(Rv)
R = Rv(r);
x(r,1) = 0.001; % initial population
for t = 1:n-1
x(r,t+1) = R*x(r,t)*(1-x(r,t)); % logistic dynamics
end
end
figure(1)
plot(G,x(1,:),'b', G,x(1,:),'go');
hold on
for r = 2:length(Rv)
plot(G,x(r,:),'-', G,x(r,:),'o')
end
hold off;
axis([1 n 0 0.45]);
title('Example of Logistic Population Dynamics')
xlabel('Generation number');
ylabel('Population (fraction of max)');
grid on
  6 Comments
Jack Farr
Jack Farr on 26 Apr 2015
This is perfect!
Thanks again, this has been a massive help. I look forwards to having a play with this.
Once again, many thanks. Jack

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!