필터 지우기
필터 지우기

Incorrect graph, loop error?

조회 수: 3 (최근 30일)
Kailin Johnsson
Kailin Johnsson 2020년 11월 17일
답변: Kailin Johnsson 2020년 11월 18일
Hello,
I am trying to run a simple malthusian model, however I have run into this error... Does anyone have an idea as to why this is happening? (I am relativly new to MATLAB).
% 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]';
%Malthusian Growth Model
% Time interval
t = (1790:10:2010)';
% Previous population
Pn = [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]';
% Growth Rate Assumption
R = (0.349)';
Labels = [1790:10:2010]';
%Malthusian Model
for i= (2:23)
E(i,1) = (Pn(i-1,1))*(R(1,1)+1)';
end
%PMal(i,1) = (r(1,1)+1)*PMal(i-1,1);
%R2
SST = sum((Pn-mean(Pn)).^2);
SSE = sum((Pn-E).^2);
R2 = 1- (SSE/SST)
% Plot
plot(t,E,'r-*');
hold on
plot (a,b,'bo');
line_color=['r'];
hold off
legend('Malthusian Model','Census Data');
axis([1790 2010 0 500]);
title('US Population Data');
ylabel('Population (Millions)');
  댓글 수: 3
Nora Khaled
Nora Khaled 2020년 11월 18일
I copied your code to try and run it...
the figure looks different
and I don't understant the model nor the problem
Kailin Johnsson
Kailin Johnsson 2020년 11월 18일
I beleive the issue was within my workspace. After clearing the space the code ran. Thank you!

댓글을 달려면 로그인하십시오.

채택된 답변

Kailin Johnsson
Kailin Johnsson 2020년 11월 18일
I beleive the issue was within my workspace. After clearing the space the code ran. Thank you!

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by