Objective function is returning Inf or NaN values at initial point. lsqcurvefit cannot continue.

Hello together,
I have a diffusion model for porous solids but I get the error message " Objective function is returning Inf or NaN values at initial point. lsqcurvefit cannot continue.". However, I dont understand it since I can calculate the values and wont get Nan or Inf values if I use a normal calculator. Is my code wrong or is it because of numerical problems? Thanks in advance
A = 0.0019634954;
R = 8.314;
T = 298.15;
N_A = 6.02214086*(10^23);
p = 100000;
k_B = 1.38064852E-23;
M = 31.999E-3;
dc = 40;
s_Kunststoff = 23E-06;
p_1 = [1; 0.1343; 0.0173; 0; 0; 0];
p_2 = [0; 0.5089; 0.4445; 0.4606; 0.3222; 0.632];
p_3 = [0; 0.0465; 0.069; 0.061; 0.067; 0.076];
p_4 = [0; 0.2407; 0.3855; 0.3641; 0.4883; 0.7211];
r_m = 15E-09;
d = 0.06E-09;
D_Knudsen = ((2/3)*r_m*((8*R*T)/(pi*M))^0.5);
D_Molekularsieb = D_Knudsen/15
D_Molekularsieb = 2.9610e-07
x = [0 5E-09 9E-09 14E-09 18E-09 25E-09]';
y = [33.20312499864E-09 19.57947530784E-09 4.079861110944E-09 1.59143518512E-09 1.456404320928E-09 1.18152006168E-09]';
modelFun = @(b,x) A.*dc./((1./(((D_Knudsen.*p_2)./(b(5).*x))+((D_Molekularsieb.*p_3)./(b(6).*x))+((b(3).*exp(-b(4)./(R.*T)))./x)))+(s_Kunststoff./(b(1).*exp(-b(2)./(R.*T)))));
b0 = [1e+03 8e+04 1e+03 8e+04 1 1]
b0 = 1×6
1000 80000 1000 80000 1 1
lb = [0 0 0 0 1 1];
ub = [1e+20 1e+20 1e+20 1e+20 30 30];
b = lsqcurvefit(modelFun,b0,x,y,lb,ub);
Error using lsqncommon
Objective function is returning Inf or NaN values at initial point. lsqcurvefit cannot continue.

Error in lsqcurvefit (line 274)
lsqncommon(funfcn,xCurrent,lb,ub,options,defaultopt,optimgetFlag,caller,...
times = linspace(x(1),x(end));
plot(x,y,'ko',times,modelFun(b,times),'b-')
legend('Data','Fitted exponential')
title('Data and Fitted Curve')

 采纳的回答

If you try this :
modelFun(b0,x)
the output has a nan. So you need to rework your function modelFun() in order to avoid this.

2 个评论

Thank you very much! That helped me to find the issue.
For anyone interested: I have a zero in my x values, so this is where the NaN comes from

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by