Help with nonlinear robost fitting on nlinfit function. fminsearch works fine but not nlinfit.

조회 수: 1 (최근 30일)
Hi
Im trying to fit some data i have to a function. I have used fminsearch and it has worked fine. Except I wanna introduce robost fitting as there are some point that make the whole fitting wrong.
I searched and found that the stat tool already has a function nlinfit that does everything for you so i thought i would use it.
However when i try to use the function in the program it says that i get NaN or Infinity which i dont get with fminsearch and with a separate m-file the data doesnt go into the other function and it says that the values are unknown.
[ndata] = given below
X = ndata(:,2:8)
dT = ndata(:,1);
par0=[2 0.2 1.5 -0.5 -0.5 -0.5]';
this doesn't send X into funtest.
par = nlinfit(X,dT,funtest,par0);
this one return NaN
%funnfit = @(par,ndata)(par(1).*ndata(:,1).^(0.5*par(2)).*ndata(:,2).^(0.5*par(3)).*ndata(:,3).^par(4).*ndata(:,4).^par(5).*ndata(:,5).^par(6));
%par = nlinfit(ndata(:,2:8),ndata(:,1),funnfit,par0);
funtest
function sse=funtest(params,A)
Pcu = A(:,1); Ptot = A(:,2); n = A(:,3); T = A(:,4); nn = A(:,5); Tr = A(:,6); L= A(:,7);
k = params(1); x = params(2); y = params(3); z = params(4); a = params(5); b = params(6);
sse=k.*Pcu.^(0.5*x).*Ptot.^(0.5*y).*n.^z.*Tr.^a.*L.^b;
ndata
1.0e+003 *
0.1085 1.3946 1.8685 0.7500 0.1000 2.6000 0.1800 0.2600
0.1007 1.3643 2.0014 1.0000 0.1000 2.6000 0.1800 0.2600
0.0943 1.3446 2.3106 1.5000 0.1000 2.6000 0.1800 0.2600
0.0877 1.3276 2.9261 2.4700 0.1000 2.6000 0.1800 0.2600
0.1080 1.8367 3.6807 3.0000 0.1000 2.6000 0.1800 0.2600
0.0680 0.7929 1.1946 0.7500 0.0750 2.6000 0.1350 0.2600
0.0657 0.7889 1.3187 1.0000 0.0750 2.6000 0.1350 0.2600
0.0624 0.7848 1.6006 1.5000 0.0750 2.6000 0.1350 0.2600
0.0607 0.7925 2.1888 2.4700 0.0750 2.6000 0.1350 0.2600
any help?

답변 (2개)

bym
bym 2012년 1월 15일
you need to tell nlinfit that funtest is a function by adding a @ in front of it. e.g.
ndata = 1.0e+003 * ...
[0.1085 1.3946 1.8685 0.7500 0.1000 2.6000 0.1800 0.2600;
0.1007 1.3643 2.0014 1.0000 0.1000 2.6000 0.1800 0.2600;
0.0943 1.3446 2.3106 1.5000 0.1000 2.6000 0.1800 0.2600;
0.0877 1.3276 2.9261 2.4700 0.1000 2.6000 0.1800 0.2600;
0.1080 1.8367 3.6807 3.0000 0.1000 2.6000 0.1800 0.2600;
0.0680 0.7929 1.1946 0.7500 0.0750 2.6000 0.1350 0.2600;
0.0657 0.7889 1.3187 1.0000 0.0750 2.6000 0.1350 0.2600;
0.0624 0.7848 1.6006 1.5000 0.0750 2.6000 0.1350 0.2600;
0.0607 0.7925 2.1888 2.4700 0.0750 2.6000 0.1350 0.2600];
X = ndata(:,2:8);
dT = ndata(:,1);
par0=[2 0.2 1.5 -0.5 -0.5 -0.5]';
par = nlinfit(X,dT,@funtest,par0);
par =
5.5529
1.0964
0.7167
-0.2858
-0.0487
-0.2793
  댓글 수: 1
bym
bym 2012년 1월 15일
generated this warning
Warning: The Jacobian at the solution is ill-conditioned, and some
model parameters may not be estimated well (they are not identifiable).
Use caution in making predictions.
> In nlinfit at 223

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


Mamed
Mamed 2012년 1월 16일
Ok thanks, that solves that but now i get the same error as the other one, that is that the modelfun returns NaN values. ndata is longer than what i typed up there. But fminsearch doesnt return an error. So i dont understand what the problem is.
Edit: I changed the starting values and it works now, however when plotting the r it says that the max of the residual is 4 but when i calculate the residuals by recalculating the function with the new parameters it gives a residual of 30.
How do i make sure that the value are the optimal ones when it all depends so much on the starting values and i just guess them???

카테고리

Help CenterFile Exchange에서 FPGA, ASIC, and SoC Development에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by