Please help with fzero function . Thanks

11 ビュー (過去 30 日間)
Jai
Jai 2023 年 11 月 4 日
回答済み: Torsten 2023 年 11 月 4 日
T_ad_n = fzero(@(a) LHS - (n(3) * (hf_0(3) + dh_CO2(a))) - (n(4) * (hf_0(4) + dh_H2O(a))),[298,6000]);
%% Where LHS = constant , n(1:5) and hf_0(1:4) already defined dh_CO2 & dh_H2O are functions in a type sym
I am getting this error
Error using fzero>localFirstFcnEvalError
FZERO cannot continue because user-supplied function_handle ==>
@(a)LHS-(n(3)*(hf_0(3)+dh_CO2(a)))-(n(4)*(hf_0(4)+dh_H2O(a))) failed with the error below.
Index exceeds the number of array elements. Index must not exceed 1.
Error in fzero (line 231)
localFirstFcnEvalError(FunFcn,FunFcnIn,ME);

採用された回答

Dyuman Joshi
Dyuman Joshi 2023 年 11 月 4 日
You need to define dh_CO2 and dh_H2O as symfun objects - symfun, i.e. both as symbolic functions of t.
Or if you can, define both as function handles of t. (or any other variable, the name of the independent variable does not matter, as long as it is a valid MATLAB name)
Right now, they are just symbolic variables, and when you use dh_CO2(a) and dh_H2O(a), MATLAB interprets it as indexing, which gives you the error, as they are scalar variables.

その他の回答 (1 件)

Torsten
Torsten 2023 年 11 月 4 日
Convert dh_CO2 and dh_H2O from symbolic functions into function handles by using "matlabFunction".
After this, they can be used as you do in
@(a) LHS - (n(3) * (hf_0(3) + dh_CO2(a))) - (n(4) * (hf_0(4) + dh_H2O(a)))

カテゴリ

Help Center および File ExchangeOptimization についてさらに検索

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by