Main Content

このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。

国勢調査のカスタム非線形近似

この例では、範囲、係数、問題依存のパラメーターを指定してカスタム式を国勢調査データに当てはめる方法を示します。

census.mat のデータを読み込み、プロットします。

load census
plot(cdate,pop,'o')
hold on

Figure contains an axes object. The axes contains a line object which displays its values using only markers.

カスタム非線形モデル y = a(x-b)n の近似オプション構造体と fittype オブジェクトを作成します。ここで、a および b は係数、n は問題依存のパラメーターです。問題依存のパラメーターの詳細については、関数 fittype のページを参照してください。

s = fitoptions('Method','NonlinearLeastSquares',...
               'Lower',[0,0],...
               'Upper',[Inf,max(cdate)],...
               'Startpoint',[1 1]);
f = fittype('a*(x-b)^n','problem','n','options',s);

近似オプションと n = 2 を使用して、データに当てはめます。

[c2,gof2] = fit(cdate,pop,f,'problem',2)
c2 = 
     General model:
     c2(x) = a*(x-b)^n
     Coefficients (with 95% confidence bounds):
       a =    0.006092  (0.005743, 0.006441)
       b =        1789  (1784, 1793)
     Problem parameters:
       n =           2
gof2 = struct with fields:
           sse: 246.1543
       rsquare: 0.9980
           dfe: 19
    adjrsquare: 0.9979
          rmse: 3.5994

近似オプションと n = 3 を使用して、データに当てはめます。

[c3,gof3] = fit(cdate,pop,f,'problem',3)
c3 = 
     General model:
     c3(x) = a*(x-b)^n
     Coefficients (with 95% confidence bounds):
       a =   1.359e-05  (1.245e-05, 1.474e-05)
       b =        1725  (1718, 1731)
     Problem parameters:
       n =           3
gof3 = struct with fields:
           sse: 232.0058
       rsquare: 0.9981
           dfe: 19
    adjrsquare: 0.9980
          rmse: 3.4944

近似結果とデータをプロットします。

plot(c2,'m')
plot(c3,'c')
legend('data','fit with n=2','fit with n=3')

Figure contains an axes object. The axes object with xlabel x, ylabel y contains 3 objects of type line. One or more of the lines displays its values using only markers These objects represent data, fit with n=2, fit with n=3.