Fzero function error in MATLAB. Need inputs regarding the ways to combat the error
2 次查看(过去 30 天)
显示 更早的评论
I can't seem to rectify this error at all.Can anyone let me know how to deal with this error? I always clear all and clc at the beginning of the code so I don't think there's a variable remaining in the workspace
Error using fzero>localFirstFcnEvalError
FZERO cannot continue because user-supplied function_handle ==>
@(c_H) closedsys(c_H,Q_rest_Na_Cl(b),v_W,k_1,k_2,ksp_CACO3,k_H,k_W,N_totCa,N_totC,v_G,T)
failed with the error below.
Array indices must be positive integers or logical values.
Error in fzero (line 295)
localFirstFcnEvalError(FunFcn,FunFcnIn,ME);
Error in line 37
c_H_zero = abs(fzero(closesys_func, c_H))
Given below is the line 295 that is in the MATLAB logs
% Put first feval in try catch
try
fx = FunFcn(x,varargin{:});
catch ME
localFirstFcnEvalError(FunFcn,FunFcnIn,ME);
end
1 个评论
回答(1 个)
Steven Lord
2024-5-24
If Q_rest_Na_Cl is a variable, is b a logical array or does it contain only integer values? If not, you cannot use b to index into Q_rest_Na_Cl.
If Q_rest_Na_Cl is a function, please show us the body of the Q_rest_Na_Cl and closedsys functions. Somewhere in there you're indexing into a variable with an invalid index (a non-integer value, a numeric 0 or a negative integer value, etc.)
You could try calling:
f = @(c_H) closedsys(c_H,Q_rest_Na_Cl(b),v_W,k_1,k_2,ksp_CACO3,k_H,k_W,N_totCa,N_totC,v_G,T)
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!