Nonlinear regression in case of many fits
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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 个评论
Jos (10584)
2013-7-18
I meant
f = polyval(p(k,:), xz)
but you probably already figured that out yourself.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Least Squares 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!