Two lines populated from one plot
4 views (last 30 days)
Show older comments
Hello,
I am working on a simple MATLAB code, and I have come across an interesting problem. I have populated multiple lines on the same graph, however when entering the last data point (red) two have populated... I have attached a picture and the code below, if anyone has any ideas why this is incorrect, please let me know! Thanks!
%Malthusian Growth Model
% Time interval
% t = (1790:10:2010)';
% Previous population
Pn = [2.91 3.929 5.308 7.239 9.638 12.866 17.069 23.191 31.443 39.818 50.189 62.947 76.212 92.228 106.021 122.775 132.164 150.697 179.323 203.302 226.545 248.709 281.421]';
% Growth Rate Assumption
R = (0.349+1)';
%Malthusian Model
E = (Pn*R)';
% Discrete Logistic Model
% Parameter and intial condtions
r= (0.349);
% Carrying Capactiy
M= 451.7;
X0= 3.929;
p= [2.913 3.929 5.308 7.239 9.638 12.866 17.069 23.191 39.818 50.189 62.947 76.212 92.228 106.021 122.775 132.164 150.697 179.323 203.302 226.545 248.709 281.421 308.745]';
% For loop to generate seqeunce terms
for i=1:length(p)
F(i)=p(i)+r*p(i)*(1-p(i)/M)';
end
tBegin = 1790; % time begin
tEnd = 2010; % time end
% Beverton-Holt Model
% Parameter and intial condtions
Pe= 486.8
a1= 1.23065
b2= 2110.5
p3= [2.913 3.929 5.308 7.239 9.638 12.866 17.069 23.191 39.818 50.189 62.947 76.212 92.228 106.021 122.775 132.164 150.697 179.323 203.302 226.545 248.709 281.421 308.745]';
% Bevholt equation
E4 = a1*(p3)/(1+(p3/b2))
% Time Interval
% a=(1790:10:2010)';
% Population
b= [3.929 5.308 7.239 9.638 12.866 17.069 23.191 31.443 39.818 50.189 62.947 76.212 92.228 106.021 122.775 132.164 150.697 179.323 203.302 226.545 248.709 281.421 308.745]';
Data = b;
Labels2 = [1790:10:1860]';
Labels = [1790:10:2010]';
% Plot all models 1790-2010
figure
plot(Labels,Data,'k-*',Labels,E,'b-*',Labels,F,'m-*', Labels,E4,'r-*')
title('Comparison of Models of US Census Data, 1790-2010')
legend('Data','Malthusian','Discrete Logistic','Beverton-Holt Model')
axis([1780 2020 0 400])
hold on

1 Comment
Accepted Answer
VBBV
on 10 Nov 2020
Change this line from
E4 = a1*(p3)/(1+(p3/b2)) % before
to
E4 = a1*(p3)./(1+(p3/b2)) % after
and plot again
More Answers (0)
See Also
Categories
Find more on General Applications in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!