nlinfit fitting error approaching infinity

조회 수: 4 (최근 30일)
Muhannad N. Fadhel
Muhannad N. Fadhel 2021년 2월 22일
답변: Deepak Meena 2021년 2월 28일
I am trying to run the code below:
However I am getting the error:
Error using nlinfit>checkFunVals (line 649)
The function you provided as the MODELFUN input has returned Inf or NaN values.
Error in nlinfit>LMfit (line 620)
if funValCheck && ~isfinite(sse), checkFunVals(r); end
Error in nlinfit (line 284)
[beta,J,~,cause,fullr] = LMfit(X,yw, modelw,beta,options,verbose,maxiter);
How can I solve this issue
A(:,:,1) = [1.17 1.2 1.22 1.23 1.25 1.27
1.18 1.21 1.22 1.23 1.25 1.25
1.19 1.21 1.22 1.23 1.24 1.24
1.2 1.22 1.22 1.22 1.23 1.22
1.2 1.21 1.22 1.22 1.22 1.22
1.2 1.21 1.21 1.21 1.21 1.2
1.2 1.2 1.2 1.2 1.2 1.19];
A(:,:,2)=[ 1.22 1.26 1.31 1.33 1.37 1.39
1.26 1.29 1.32 1.33 1.36 1.37
1.27 1.3 1.32 1.33 1.36 1.36
1.28 1.31 1.33 1.34 1.35 1.34
1.29 1.31 1.32 1.33 1.34 1.33
1.29 1.3 1.31 1.32 1.32 1.31
1.29 1.3 1.31 1.31 1.31 1.29];
A(:,:,3) = [1.29 1.34 1.37 1.41 1.45 1.47
1.31 1.36 1.4 1.42 1.44 1.45
1.33 1.38 1.41 1.41 1.43 1.43
1.35 1.39 1.41 1.41 1.42 1.41
1.35 1.39 1.41 1.41 1.41 1.4
1.36 1.38 1.4 1.39 1.4 1.38
1.36 1.38 1.39 1.39 1.39 1.37];
K = 60:10:120;
C = [0 0.1 0.2 0.3 0.6 0.9];
X = [7 10 13.5].^2/100^2;
[c, k, x] = meshgrid(C, K, X);
% % % MAPPING: x = ckx(:,1), y = ckx(:,2), z = ckx(:,3), a = b(1), b= B(2), c = b(3), d = b(4)
ckx = [c(:) k(:) x(:)];
Eq = @(b,ckx) ((b(8).*ckx(:,2).*ckx(:,1)) + 1).*(b(1).*ckx(:,2) + b(2).*(ckx(:,1)).^b(3)).* ckx(:,3).^(b(4).*ckx(:,2)+b(5).*(ckx(:,1)+1).^b(6)) + b(7);
B = nlinfit(ckx, A(:), Eq, [0.01, 1, 1, 0.01, 0.1, 0.1, 0.1, 0.00001]);
plot(A(:)); hold on; plot(A(:)-R)
xticks([4:7:126])
xticklabels([0 0.1 0.2 0.3 0.6 0.9 0 0.1 0.2 0.3 0.6 0.9 0 0.1 0.2 0.3 0.6 0.9])

답변 (1개)

Deepak Meena
Deepak Meena 2021년 2월 28일
Hi Muhannad Fadhel,
From my understanding , your initial values of the parameters seems to be problem since you are using exponential terms
Using this answer, I changed the initial values to
[0.01, 1, 0.09, 0.0018, 0.1, 0.19, 0.1, 0.00001]
It doesn't give the Nan or Inf error but this might not be the best starting values you neeeded for your dataset.

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by