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

7 ビュー (過去 30 日間)
Uditangshu
Uditangshu 2024 年 5 月 24 日
回答済み: Steven Lord 2024 年 5 月 24 日
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 件のコメント
Matt J
Matt J 2024 年 5 月 24 日
No, there's nothing we can tell you without being able to run your code.

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

回答 (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 Center および File ExchangeVariables についてさらに検索

タグ

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by