Aproximare MCMMP

Recensamantul SUA

Datele de mai jos au fost inregistrate de US Census intre 1900 si 2010

%CENSUS - example with census data

% polynomial fit

%population

y = [ 75.995 91.972 105.711 123.203 131.669 150.697 ...

179.323 203.212 226.505 249.633 281.422 308.786]';

t = (1900:10:2010)'; % census years

Dorim sa modelam datele si sa facem predictii pentru anii 1975 si 2015

x = (1890:1:2019)'; % evaluation years

w = [1975,2015]; % prediction years

Vom modela datele printr-un polinom de gradul 3

Fitting direct

c=polyfit(t,y,3)

Warning: Polynomial is badly conditioned. Add points with distinct X values, reduce the degree of the polynomial, or try centering and scaling as described in HELP POLYFIT.
c =
  -6.5861e-06     0.047733         -109        80029

Rezultatele sunt inacceptabile din punct de vedere numeric.

Vom normaliza datele cu

mt=mean(t); st=std(t);

s=(t-mt)/st;

xs=(x-mt)/st;

Fitting cu date normalizate

coeficientii

cs=polyfit(s,y,3)

cs =
     -0.30871       11.837       76.561       166.49

predictiile

zs=polyval(cs,xs);

est=polyval(cs,(w-mt)/st);

reprezentare grafica

plot(t,y,'o',x,zs,'-',w,est,'*')

for i=1:length(w)

text(w(i),est(i)-20,num2str(est(i)))

end

title('U.S. Population', 'FontSize', 14)

xlabel('year', 'FontSize', 12)

ylabel('Millions', 'FontSize', 12)