Please help with fzero function . Thanks
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Dyuman Joshi
le 4 Nov 2023
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 commentaires
Plus de réponses (1)
Torsten
le 4 Nov 2023
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 commentaires
Voir également
Catégories
En savoir plus sur Optimization dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!