how to code to solve for coefficient using linear regression?

조회 수: 4 (최근 30일)
rocket
rocket 2012년 11월 15일
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
Sean de Wolski
Sean de Wolski 2012년 11월 15일
+1, Good question effort, and prodding for interesting answers!

댓글을 달려면 로그인하십시오.

답변 (2개)

Tom Lane
Tom Lane 2012년 11월 15일
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 2012년 11월 15일
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.

제품

Community Treasure Hunt

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

Start Hunting!

Translated by