how to code to solve for coefficient using linear regression?

1 visualización (últimos 30 días)
rocket
rocket el 15 de Nov. de 2012
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..

Respuestas (2)

Tom Lane
Tom Lane el 15 de Nov. de 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
Star Strider el 15 de Nov. de 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.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by