Code running in one tab, but not another
Show older comments
Hi all,
I am running a code (attached below) and there is an error... although I have run the same code just with more values for data perfectly fine. I have also attached a pciture of the error in case that helps. Does anyone have any ideas why this might be? Thanks

% Plot all models 1790-1860
%Malthusian Growth Model
% Time interval
% t = (1790:10:1860)';
% Previous population
Pn = [2.913 3.929 5.308 7.239 9.638 12.866 17.069 23.191]';
% 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= [3.929 5.308 7.239 9.638 12.866 17.069 23.191 31.443]';
% 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 = 1860; % time end
%Gompertz Model
% Time Interval
% a=(1790:10:1860)';
% Population
b= [3.929 5.308 7.239 9.638 12.866 17.069 23.191 31.443]';
Data = b;
k2 = 330.0;
B = log(Data(2:23,1)./k2);
A = log(Data(1:22,1)./k2);
X = A\B;
b = -log(X(1,1));
P0 = Data(1,1);
LL = zeros(23,1);
LL(1,1) = P0;
for i = 2:23
LL(i,1) = exp((exp(-b)).*log(LL(i-1,1))+((1-exp(-b)).*log(k2)));
end
% Single Plot
% figure
% plot(Labels,Data,'b-*',Labels,PG,'r-*')
% title('Gompertz Model, 1790-1860')
% legend('Data','Model','Location','northwest')
% hold on
%R2
SST = sum((Data-mean(Data)).^2);
SSE = sum((Data-LL).^2);
R2 = 1- (SSE/SST)
% Beverton-Holt Model
% Parameter and intial condtions
Pe= 486.8
a1= 1.23065
b2= 2110.5
p3= [3.929 5.308 7.239 9.638 12.866 17.069 23.191 31.443]';
% Bevholt equation
E4 = a1*(p3)./(1+(p3/b2))
% Time Interval
% a=(1790:10:1860)';
% Population
b= [3.929 5.308 7.239 9.638 12.866 17.069 23.191 31.443]';
Data = b;
Labels2 = [1790:10:1860]';
Labels = [1790:10:2010]';
% Plot all models 1790-1860
figure
plot(Labels,Data,'k-*',Labels,E,'r-*',Labels,F,'b-*',Labels,LL, 'm-*', Labels,E4,'g-*')
title('US Population Data, 1790-1860')
legend('Data','Malthusian','Discrete Logistic','Gompertz','Beverton-Holt Model')
ylabel('Population (Millions)');
xlabel ('Years')
axis([1780 1860 0 200])
hold on
Accepted Answer
More Answers (0)
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!