I have been trying to fix the problem of this code but unfortunately It keep saying ERORR on line 71 which is [y= dfl(xo)\fl(xo)]. Need to help?
1 view (last 30 days)
Show older comments
function[final_comp]=eq_model_const(g_temp,ele_comp,m)
format short
tol=0.00001;
maxit=100;
%disp('elemental composition should be of the form [C, H, O, N, Ash]');
%ele_comp=input('Enter elemental composition of biomass: ');
%disp('Initial guess is of the form [H2 CO CO2 H2O CH4] ')
xx0=[0.1,0.1,0.1,0.1,0.1]';
% Heat of formation of different compounds at 25 C, kJ/kmol
H_f_H2O_g=-241818;H_f_H2O_l=-285830;H_f_CO2=-393509;H_f_CO=-110525;
H_f_CH4=-74520;H_f_H2=0;H_f_O2=0;H_f_N2=0;
%Function for finding sensible heat for various gases constants
C_p_H2O=[32.24 0.1923e-2 1.055e-5 -3.595e-9];
C_p_H2=[29.11 -0.1916e-2 0.4003e-5 -0.8704e-9];
C_p_CO=[28.16 0.1675e-2 0.5372e-5 -2.222e-9];
C_p_CO2=[22.26 5.981e-2 -3.501e-5 -7.469e-9];
C_p_CH4=[19.89 5.204e-2 1.269e-5 -11.01e-9];
C_p_N2=[28.90 -0.1571e-2 0.8081e-5 -2.873e-9];
%finding general equations for calculating k1 and k2
G_CO=[3.376 0.557e-3 0 -0.031e5 -110525 -137169];
G_CO2=[5.457 1.045e-3 0 -1.157e5 -393509 -394359];
G_H2O=[3.470 1.450e-3 0 0.121e5 -241818 -228572];
G_H2=[3.249 0.422e-3 0 0.083e5 0 0];
G_C=[1.771 0.771e-3 0 -0.867e5 0 0];
G_CH4=[1.702 9.081e-3 -2.164e-6 0 -74520 -50460];
delta_ws_final=[];
delta_meth_final=[];
for iii=1:6
delta_ws=G_H2(iii)+G_CO2(iii)-G_CO(iii)-G_H2O(iii);
delta_meth=G_CH4(iii)-G_C(iii)-2*G_H2(iii);
delta_ws_final=[delta_ws_final delta_ws];
delta_meth_final=[delta_meth_final delta_meth];
end
T_0=298.15;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
k1= 9.72e-02;
k2= 1.14561;
%%%%%%%%function for calculating int_eq_sp
function int_for_gibbs_difff1= int_eq_sp1(difff,g_temp)
tau=g_temp/298.15;
int_for_gibbs_difff1=difff(1).*log(tau)+((difff(2).*T_0+((difff(3)*T_0^2+(difff(4)/(tau^2.*T_0^2)))*((tau+1)/2)))*(tau-1));
end
%%%%%%%%%%%%%%%%%%%%
function int_for_gibbs_difff2= int_eq_sp2(var_sp,g_temp)
tau=g_temp/298.15;
int_for_gibbs_difff2=var_sp(1).*T_0*(tau-1)+var_sp(2)*0.5*T_0^2*(tau^2-1)+var_sp(3)*T_0^3*(tau^3-1)/3+var_sp(4)*(tau-1)/(tau*T_0);
end
%k1=9.72e-02;k2=1.4561;
%%%%finding lambda and gamma for below calculations%%%%%%%%%%%%%%%%%%%%%%%%%
norm_1_C = 20/(12);
norm_1_H = 25/(1.008);
norm_1_O = 35/(16);
norm_1_N= 25 /(14.007);
lambda = norm_1_H/norm_1_C ;
gamma = norm_1_O/norm_1_C ;
beta = norm_1_N/norm_1_C ;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
x0=xx0;
iter=1;
iter_m=1;
sol_final=[];
w=0;
Moisture_Content=[];
for N=1:length(w)
Moisture_Content=[Moisture_Content 18*100*w(N)/(24+18*w(N))];
end
Moisture_Content;
%%%%%%%%%%%%%%%%%Main Loop for solving the equations of interests
for iter_m=1:length(w)
while(iter<=maxit)
y =-dfl(x0)\f1(x0);
xn=x0+y;
err=max(abs(xn-x0));
if(err<=tol)
x=xn;
else
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
x0=xn;
end
iter=iter+1;
end
iter=1;
sol_temp=x;
sol_final=[sol_final sol_temp];
iter_m=iter_m+1;
end
%Multiplying m with 3.76 to get correct N2 moles
p=length(w);
frac_N2=[];
for l=1:p
frac_N2=[frac_N2 m*3.76];
end
final_comp=[sol_final(1:5,1:p);frac_N2];
%fin_rep=input('Do you want to find syngas composition in dry syngas basis(y/n): ','s');
fin_rep='n';
if fin_rep=='n';
%finding total amount of product gas for each moisture content
total_frac_m=[];
for n=1:p
total_frac_m=[total_frac_m sum(final_comp(1:6,n))];
end
total_frac_m; %sum of all product gases
else
%finding total amount of product gas on dry basis for each moisture content
dry_final_comp=final_comp;
dry_final_comp(4,:)=[];
total_frac_m=[];
for n=1:p
total_frac_m=[total_frac_m sum(dry_final_comp(1:5,n))];
end
total_frac_m;
final_comp=dry_final_comp;
end
%expressing all the components in molar fraction or volumetric fraction
final_frac_comp=[];
for MM=1:length(total_frac_m)
final_frac_m=[];
if fin_rep=='y'
l_in=length(xx0);
else
l_in=length(xx0)+1;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for NN=1:l_in
inal_frac_m=[final_frac_m;final_comp(NN,MM)/total_frac_m(MM)];
end
final_frac_comp=[final_frac_comp final_frac_m];
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function f=f1(X)
x_1=X(1); x_2=X(2); x_3=X(3);x_4=X(4);x_5=X(5);
val_1=x_2+x_3+x_5-1;
val_2=x_1+x_4+2*x_5-w(iter_m)-(lambda/2);
val_3=x_2+2*x_3+x_4-2*m-gamma-w(iter_m);
val_4=-k1*x_1^2+(x_5*(x_1+x_2+x_3+x_4+x_5+3.76*m));
val_5=x_2*x_4*k2-x_1*x_3;
f=[val_1; val_2;val_3;val_4;val_5];
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function df=df1(X)
x_1=X(1); x_2=X(2); x_3=X(3);x_4=X(4);x_5=X(5);
df=[0,1,1,0,1;1 0 0 1 2; 0 1 2 1 0;-2*x_1*k1+x_5,x_5,x_5,x_5,2*x_5+(x_1+x_2+x_3+x_4+3.76*m); -x_3 k2*x_4-x_1 k2*x_2 0];
end
end
THIS WAS THE ERORR DISPLAYED
Unrecognized function or variable 'dfl'.
Error in eq_model_const (line 71)
y =-dfl(x0)\f1(x0);
2 Comments
John D'Errico
on 23 Jan 2023
Edited: John D'Errico
on 23 Jan 2023
What is the error? You do not tell us what the COMPLETE error is, so someone would need to ty to run the code. But you do not provide sufficient information to know even how you ran the code. That makes it impossible to help you.
When you ask about an error, REPORT THE COMPLETE ERROR. EVERYTHING IN RED.
Show how you called the function, and with what inputs, since this is a function.
Better yet would be to learn to use the debugger, in which case you might be able to solve the problem yourself. But at least make it possible for someone to help you.
Accepted Answer
Jan
on 7 Feb 2023
Edited: Jan
on 7 Feb 2023
"Unrecognized function or variable 'dfl'." - The error message seems to be clear: The expression "dfl" is unknown. Do you expect it to be an array or a function? Where is it defined?
Your code contains a function called "df1" - D-F-One, while the failing line contains "dfl" - D-F-lowercase L. Maybe this is a typo only?
Use a font, in which l (lowercase L) and 1 (one) and I (uppercase i) looks different. The same problem concerns O (uppercase oh) and 0 (zero).
4 Comments
Jan
on 12 Mar 2023
@Aspetos Truth: Please use the tools to format code. This improves the readability.
ans =
48.3100 6.2800 44.1500 0.5300 0.7300
This is the answer to what?
You define the function with input arguments:
function[final_comp]=eq_model_const(g_temp,ele_comp,m)
But then the inputs are overwritten by input() commands. Prefer to call the function with input arguments instead:
eq_model_const(600, [48.31, 6.28, 44.15, 0.53, 0.73], 0.3)
and omit the input() lines. Then the calls are reproducible.
More Answers (0)
See Also
Categories
Find more on Visualization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!