Nonlinear regression in case of many fits
조회 수: 5 (최근 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!