数值实验四 2 PDF

You might also like

You are on page 1of 2

拟合图形如下:

可见拟合效果一般,拟合曲线后端变化趋势与实际曲线出现了很大的偏差。如果使用线性函数
来拟合效果会更好:

MATLAB程序:
x = [1953; 1964; 1982; 1990; 2000];
y = [5.82; 6.95; 10.08; 11.34; 12.66];
xy = x.*y;
A = [ones(size(x)), x, -xy];
p = A\y;
a = p(1)
b = p(2)
c = p(3)
plot(x, y, 'o--')
hold on
x_fit = min(x):1:max(x);
y_fit = (a+b.*x_fit)./(1+c.*x_fit);
plot(x_fit, y_fit,'-')
xlabel('Year')
ylabel('Population')
legend('actual','fit','location','SouthEast')

% 线性拟合
%x = [1953; 1964; 1982; 1990; 2000];
%y = [5.82; 6.95; 10.08; 11.34; 12.66];
%xy = x.*y;
%A = [ones(size(x)), x];
%p = A\y;
%a = p(1)
%b = p(2)
%plot(x, y, 'o--')
%hold on
%x_fit = min(x):1:max(x);
%y_fit = a+b.*x_fit;
%plot(x_fit, y_fit,'-')
%title('Linear fitting')
%xlabel('Year')
%ylabel('Population')
%legend('actual','fit','location','SouthEast')
%imsave('fig.png')

运行结果:

a =  2.9456
b = -0.0014066
c = -4.9560e-04

You might also like