Please help with fzero function . Thanks
11 ビュー (過去 30 日間)
古いコメントを表示
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);
0 件のコメント
採用された回答
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.
0 件のコメント
その他の回答 (1 件)
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)))
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!