Nonlinear regression in case of many fits

1 回表示 (過去 30 日間)
Ede gerlderlands
Ede gerlderlands 2013 年 7 月 17 日
I have tried to fit certain data points using equation of the form y=ax^-1/3. My first question is , Is it possible to linearise the equation as I do in the code below? The other problem is that how can I get the coefficients in case of many regression fits as indicated in the for loop. Here is the code I tried. The loop doesn't give me as many coefficients as equal to w. Only one coefficient is obtained.
for w= 1:3684
z(:,w) = R(1:12,w).^-1/3;
y(:,w)=S(1:12,w);
p(w,:) = polyfit(z,y,1);
%yy = p(1) * z + p(2);
f = polyval(p,z(:,w));
plot(R(1:12,w),y(:,w),'o',R(1:12,w),f(:,w),'-')
end

採用された回答

Jos (10584)
Jos (10584) 2013 年 7 月 18 日
First, note this
x = [1 6 9]
x.^-1/3
x.^(-1/3)
(x.^-1)/3
Then, you do not need to store z and w. Here is a more efficient solution:
idx = [1 10 100 3684] ;
N = numel(idx) ;
p = zeros(N,2) ; % pre-allocation
for k = 1:N
w = idx(k) ;
x = R(1:12,w) ;
xz = x.^-1/3;
y = S(1:12,w);
p(k,:) = polyfit(xz,y,1);
f = polyval(p,xz) ;
plot(x, y, 'o', x, f, '-')
end
If you want to store the fitted values as well, pre-allocate f
f = zeros(12,N) ;
...
f(:,k) = polyval(p,xz) ;
  3 件のコメント
Ede gerlderlands
Ede gerlderlands 2013 年 7 月 18 日
Thank you. This take my burden away ..
Jos (10584)
Jos (10584) 2013 年 7 月 18 日
I meant
f = polyval(p(k,:), xz)
but you probably already figured that out yourself.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeRegression についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by