參考程式碼:
t = 2004:2012;
x = [714.33 720.22 730.51 759.67 780.37 798.62 833.89 843.23 857.97];
% 模型一: 指數增長模型。
y = log(x);
a = polyfit(t,y,1);
r = a(1);
x0 = exp(a(2));
x1 = x0 * exp(r*t);
% 模型二:阻滯增長模型
f = @(a,t) a(1)./(1+(a(1)/x(1)-1)*exp(-a(2)*(t-t(1))));
a = lsqcurvefit(f,[880 1],t,x);
plot(t,x,"o",t,x1,"r:.")
x2 = f(a,t);
plot(t,x,"o",t,x1,"r:.",t,x2,"g*--")
legend("原始資料","指數增長模型","阻滯增長模型",2)
xlabel 年份; ylabel 人口(萬人)
參考程式碼:
t = 2004:2012;
x = [714.33 720.22 730.51 759.67 780.37 798.62 833.89 843.23 857.97];
% 模型一: 指數增長模型。
y = log(x);
a = polyfit(t,y,1);
r = a(1);
x0 = exp(a(2));
x1 = x0 * exp(r*t);
% 模型二:阻滯增長模型
f = @(a,t) a(1)./(1+(a(1)/x(1)-1)*exp(-a(2)*(t-t(1))));
a = lsqcurvefit(f,[880 1],t,x);
plot(t,x,"o",t,x1,"r:.")
x2 = f(a,t);
plot(t,x,"o",t,x1,"r:.",t,x2,"g*--")
legend("原始資料","指數增長模型","阻滯增長模型",2)
xlabel 年份; ylabel 人口(萬人)