how to code to solve for coefficient using linear regression?
Mostra commenti meno recenti
I have a equation y=ax^b*e^(cx). I linearized this as lny= lna+ blnx+cx. Now i need to find the coefficients a, b and c. which method should i use. please let me know as soon as possible.
Thank You in advance for ur help..
1 Commento
Sean de Wolski
il 15 Nov 2012
+1, Good question effort, and prodding for interesting answers!
Risposte (2)
Tom Lane
il 15 Nov 2012
It is hard to know what method you should use without understanding the problem more. One method is this. Suppose x and y are column vectors:
d = [ones(size(x)), log(x), x] \ log(y)
a = exp(d(1)), b = d(2), c = d(3)
Star Strider
il 15 Nov 2012
I suggest that you not linearize it. That distorts the errors, and the estimated parameters will not be accurate. Instead, use an anonymous function such as:
% a = B(1), b = B(2), c = B(3)
yfcn = @(B,x) B(1) .* x.^B(2) .* exp(B(3).*x);
then:
Beta0 = rand(3,1);
[Beta,R,J,CovB,MSE] = nlinfit(x, y, yfcn, Beta0); % Statistics Toolbox
or:
[Beta,resnorm,residual,exitflag,output,lambda,jacobian] = lsqcurvefit(yfcn, Beta0, x, y); % Optimization Toolbox (allows parameter constraints)
The values of Beta correspond to a, b, and c, in order.
If you do not have access to the Statistics or Optimization Toolboxes, I suggest you use fminsearch and the examples in Curve Fitting via Optimization. (The documentation explains it better than I could.) In that example, replace the FittedCurve line with:
FittedCurve = params(1) .* xdata.^params(2) .* exp(params(3).*xdata);
which is the code for your function.
Categorie
Scopri di più su Linear Predictive Coding in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!