필터 지우기
필터 지우기

Fzero function error in MATLAB. Need inputs regarding the ways to combat the error

조회 수: 5 (최근 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개)

Steven Lord
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)
with the c_H you use as your initial guess and step through the closedsys function in the Debugger.

카테고리

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

태그

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by