Error using fzero on line 306 with function handles
古いコメントを表示
I am trying to write a script that given a set of polynomials that correspond to Cp values of different molecular components you can find the Adiabatic flame temperature.
This is my code thus far:
%The components polynomials
p_CO2 = [7.469e-9,-3.501e-5,5.981e-2,22.26];
p_N2 = [-2.873e-9,0.8081e-5,-0.1571e-2,28.90];
p_H2O = [-3.595e-9,1.055e-5,0.1923e-2,32.24];
%If I am trying to find T do I need to evaluate the polynomials at a T?
%polyval(p_CO2, 1000);
%polyval(p_N2,1000);
%polyval(p_H2O,1000);
%Variables for equation
N_ethyl = 1;
hf0_ethyl = -277690;
N_h2o = 0.0919;
hf0_h2o = -241820;
N_co2 = 2;
hf0_co2 = -393520;
N_H2O = 3;
N_n2 = 11.28;
%Cp equations for the components
cp_CO2 = @(T) polyval(p_CO2, T);
cp_N2 = @(T) polyval(p_N2, T);
cp_H2O = @(T) polyval(p_H2O, T);
%Delta h equations from reference temp(298K) to an adiabatic flame temp.
delta_h_CO2 = @(T) integral(cp_CO2,298,T);
delta_h_N2 = @(T) integral(cp_N2,298,T);
delta_h_H2O = @(T) integral(cp_H2O,298,T);
f = @(T) (N_co2(hf0_co2+(delta_h_CO2)) + N_H2O(hf0_h2o+(delta_h_H2O)) + N_n2(delta_h_N2)) - ((N_ethyl*(hf0_ethyl)) + (N_h2o*(hf0_h2o)));
fzero( f, 2500)
%Since the goal of this problem is to find the T that is the upper limit of
%the integral, I'm not sure what the issue would be.
And I keep receiving this error message, any assistance would be apprecaited! Still a bit rusty on MATLAB trying to learn more applications for it.
Error using fzero (line 306)
FZERO cannot continue because user-supplied function_handle ==>
@(T)(N_co2(hf0_co2+(delta_h_CO2))+N_H2O(hf0_h2o+(delta_h_H2O))+N_n2(delta_h_N2))-((N_ethyl*(hf0_ethyl))+(N_h2o*(hf0_h2o))) failed with the
error below.
Undefined function 'plus' for input arguments of type 'function_handle'.
Error in ThermoScript (line 33)
fzero( f, 2500)
回答 (2 件)
f was not using T at all,
f = @(T) (N_co2(hf0_co2+(delta_h_CO2(T))) + N_H2O(hf0_h2o+(delta_h_H2O(T))) + N_n2(delta_h_N2(T))) - ((N_ethyl*(hf0_ethyl)) + (N_h2o*(hf0_h2o)));
1 件のコメント
Torsten
2019 年 5 月 2 日
f = @(T) (N_co2*(hf0_co2+delta_h_CO2(T)) + N_H2O*(hf0_h2o+delta_h_H2O(T)) + N_n2*delta_h_N2(T)) - (N_ethyl*hf0_ethyl + N_h2o*hf0_h2o);
Steven Lord
2019 年 5 月 2 日
The error is correct, you cannot add function handles.
f1 = @(x) sin(x);
f2 = @(x) cos(x);
f3 = @(x) f1 + f2;
f3(pi/4) % Throws this error
What you can do is add the values returned by evaluating those function handles.
f1 = @(x) sin(x);
f2 = @(x) cos(x);
f3 = @(x) f1(x) + f2(x);
f3(pi/4) % Works and returns sin(pi/4)+cos(pi/4)
2 件のコメント
Christian Knutson
2019 年 5 月 2 日
Matt J
2019 年 5 月 2 日
@Christian,
Please Accept-click answers when they fulfill what you want.
カテゴリ
ヘルプ センター および File Exchange で Animation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!