Nonlinear regression in case of many fits
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Jos (10584)
le 18 Juil 2013
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 commentaires
Jos (10584)
le 18 Juil 2013
I meant
f = polyval(p(k,:), xz)
but you probably already figured that out yourself.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Least Squares dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!