Error "First input argument must be a function handle." function used fzero Please help to resolve the issue. Thanks

LHS = n(1) * (hf_0(1) + dh_CH4 ) + n(2) * (hf_0(2) + dh_O2); % I holds a double
%function [T_ad] = usolver(dh_CH4,dh_O2,n,hf_0,dh_CO2,dh_H2O,epsilon)
n = [1,2,1,2];
hf_0 = [-74873 , 0, -39352, -241826];
f = @(x) (- n(3) * (hf_0(3) + dh_CO2(x)) - n(4) * (hf_0(4) + dh_H2O(x))) + LHS ; % dh_CO2 & dh_H2O are functions in x
fzero(f,1000)
Error using fzero>localFirstFcnEvalError
FZERO cannot continue because user-supplied function_handle ==> @(x)(-n(3)*(hf_0(3)+dh_CO2(x))-n(4)*(hf_0(4)+dh_H2O(x))) failed with the error below.
First input argument must be a function handle.

 采纳的回答

The assignment statements are out-of-order (so ‘n’ and ‘hf_0’ do not yet exist when they are assigned in ‘LHS’) and two functons and two variable values are missing.
Supply the correct functions and values values and it should actually produce a useful result —
%function [T_ad] = usolver(dh_CH4,dh_O2,n,hf_0,dh_CO2,dh_H2O,epsilon)
dh_CO2 = @(x) sin(x);
dh_H2O = @(x) cos(x);
dh_CH4 = 1/42;
dh_O2 = 1/42^2;
n = [1,2,1,2];
hf_0 = [-74873 , 0, -39352, -241826];
LHS = n(1) * (hf_0(1) + dh_CH4 ) + n(2) * (hf_0(2) + dh_O2); % I holds a double
f = @(x) (- n(3) * (hf_0(3) + dh_CO2(x)) - n(4) * (hf_0(4) + dh_H2O(x))) + LHS ; % dh_CO2 & dh_H2O are functions in x
fzero(f,1000)
Exiting fzero: aborting search for an interval containing a sign change because NaN or Inf function value encountered during search. (Function value at -Inf is NaN.) Check function or try again with a different starting value.
ans = NaN
.

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Test and Measurement 的更多信息

产品

版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by