%预测人口数和实际人口数对比
%用拟合的方法预测人口数
year = [2009:1:2018]
population = [133126,133770,134413,135069,135738,136427,137122,137866,138639,139538]
%2019-2022人口数据
pre_year = 2019:2022
pre_pop = [140774.5,141110,141236,141175]
%cftool
[fitresult, gof] = createFit(year, population)
x = 2018:2022
p1 = 702.4
p2 = -1.278e+06
predictions = p1*x+p2
figure(2)
plot(year,population,'o',x,predictions,'b-') % 绘制预测结果图
%绘制比较图
figure(3)
plot(year,population,'o',x,predictions,'+',pre_year,pre_pop,'*')
legend('function fit 1', 'predictions','truth','Location', 'NorthEast', 'Interpreter', 'none' )
%数据不够,所以在19年以后出现变化