フィルターのクリア

error with fsolve (error using trustnleqn)

2 ビュー (過去 30 日間)
beginner
beginner 2016 年 3 月 13 日
回答済み: Star Strider 2016 年 3 月 13 日
Hi,
I get this error and I really have no idea what it is about... :/
I really really need to solve this... please HELPPP
Warning: Infinite or Not-a-Number value encountered.
> In integralCalc/iterateScalarValued (line 349)
In integralCalc/vadapt (line 132)
In integralCalc (line 83)
In integral (line 88)
In vdW_layer (line 30)
In ex5 (line 7)
In ex5_main>@(A_CL)ex5(A_CL,delta_GL,N)
In fsolve (line 230)
In ex5_main (line 8)
Error using trustnleqn (line 28)
Objective function is returning undefined values at initial point. FSOLVE
cannot continue.
Error in fsolve (line 388)
trustnleqn(funfcn,x,verbosity,gradflag,options,defaultopt,f,JAC,...
Error in ex5_main (line 8)
A_CL = fsolve(fun5, A_CL_init);
my code is following.... ex5:
delta_GL = 3.28*10^-10; %[m]
N = 100;
fun5 = @(A_CL) ex5(A_CL,delta_GL, N);
A_CL_init = 10e-76; %initial guess
A_CL = fsolve(fun5, A_CL_init);
and ex5 is:
function F = ex5(A_CL,delta_GL, N)
% Constants
theta = 86/180*pi;
gamma_L = 0.0728; %[J/m^2]
F = gamma_L*(1+cos(theta))-vdW_layer(delta_GL, A_CL,N);
end
and vdW_layer is...
function Phi_NL = vdW_layer(delta_GL, A_CL,N)
% delta_GL = 1e9;
% A_CL = 1e-5;
% N = 100;
% Constants
a = 2.49 * 10^(-10); % [m]
sigma = 4/(sqrt(3)*a^2); % surface density of carbon atoms
d0 = 3.35 * 10^(-10) ; % [m] interlayer distance
k_B = 1.38064852*10^(-23);
T = 298; % room temperature (25) [K]
rho_L = 3.34*10^28; % water density [nr of molecular/m^3]
Phi_NL = 0;
%sum_w0 = 0;
range = 1:N;
clc
for k = range
% sum_w = @(z) sum_w0 + 1./(z + (i-1)*d0).^4;
% sum_w = @(z,j)(1./(z + (j-1)*d0).^4);
funw2 = @(z,range) funw(z,range);
w = @(z) -pi*sigma*A_CL/2.* funw2(z,range);
rho = @(z) rho_L*exp(-w(z)/(k_B*T));
fun = @(z) rho(z) .* -pi*sigma*A_CL./(2*(z+(k-1)*d0).^4);
Int_NL = integral(fun, delta_GL, inf);
Phi_NL = Phi_NL + Int_NL;
end
with a subfunction:
function wsum = funw(z,range)
d0 = 3.35 * 10^(-10) ; % [m] interlayer distance
wsum =0;
for j=range
wsum = wsum + (1./(z + (j-1)*d0).^4);
end
  1 件のコメント
Geoff Hayes
Geoff Hayes 2016 年 3 月 13 日
beginner - the error message is telling you that your functions are producing an invalid result. Is your code adequately checking for division by zero errors? You may need to call (just prior to running your main function)
dbstop if error
so that the debugger pauses at the line of code that is generating the error. You may be able to get an idea of why your software has entered an invalid state.

サインインしてコメントする。

回答 (1 件)

Star Strider
Star Strider 2016 年 3 月 13 日
I did not run your code (it’s difficult to follow), but just looking at it, most of your constants are extreme, and your initial estimate:
A_CL_init = 10e-76; %initial guess
is as well.
It is quite likely responsible for throwing the error:
Objective function is returning undefined values at initial point. FSOLVE cannot continue.
I would start with a much larger initial guess, perhaps 1E-3, then see the result. Since your function could have local minima, reduce the initial guess until fsolve converges successfully (function value close to zero) and you believe the parameter estimate to be reasonable.

カテゴリ

Help Center および File ExchangePerformance and Memory についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by