nonlinear regression
조회 수: 4 (최근 30일)
이전 댓글 표시
After spending five hours reading how to use matlab for nonlinear regression I am so confused. I'm sure there must be some simple way to use a Non linear regression.
I have a function
y = m*x+d*g+d*(g^(1/k)+b^2+(b-x)^2)^k
where Im trying to find parameters m,d,g,k,b with 0<k<1
I have (x,y) data such as
(0.01, 0.00000020369272)
(0.02, 0.00000040738543)
(0.03, 0.00000061107815)
etc...
Is there some simple way to use Matlab to find the parameters?
댓글 수: 0
채택된 답변
Matt Tearle
2011년 2월 21일
If you have Statistics Toolbox, you can use nlinfit, although there's no guarantee that k will be in the interval (0,1). Make a function handle to your function:
f = @(c,x) c(1)*x+c(2)*c(3)+c(2)*(c(3)^(1/c(4))+c(5)^2+(c(5)-x).^2).^c(4);
f is a function of the parameters ( c ) and x. Make an initial guess of the parameters:
c = rand(5,1);
Then call nlinfit with the data you have:
cfit = nlinfit(xdata,ydata,f,c)
If you don't have Stats TB, you can brute-force it in MATLAB by making an error function to minimize. Define f as above. Then define
g = @(c) norm(f(c,xdata)-ydata);
Now use fminsearch to find the coefficients, starting with an initial guess (as before)
cfit = fminsearch(g,c)
If you have Optimization Toolbox, you can use fmincon to constrain k.
댓글 수: 4
Ho Nam Ernest Yim
2018년 4월 4일
편집: Ho Nam Ernest Yim
2018년 4월 4일
Can I know are there any other methods I can use also to compare the performances among methods. I used nlinfit and lsqcurvefit, I looked up and found fitnlm and lsqnonlin are same as the about methods. And I have looked into different methods such as ridge , robust , polyfit but none of them fit the case that lsqcurvefit is considering : as in lsqcurvefit(fun,x0,xdata,ydata) *nonlinear case Please help me =( , I have been looking at it for a while
Mohamad Mossad
2018년 11월 12일
Can I ask how to initialize the parameters in a better way, so that it doesn't change with every run because random numbers don't really solve the problem?
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!