Not enough input arguments; fzero function

3 visualizaciones (últimos 30 días)
Kareemulla Dudekula
Kareemulla Dudekula el 15 de Abr. de 2022
Comentada: Kareemulla Dudekula el 18 de Abr. de 2022
Dear All,
My follwoing code invoking fzero results in an error, 'Not enough input arguemnts'; I cannot quite figure out where the problem is. Any inputs are greately appreciated.
clc; clear all; close all;
global R mole_frac Cp T_Ref Avg_Cp_Bub_mix Avg_Cp_EG_mix T
R = 8.314; T_Ref = 298;
Cp_1 = [3.376; 0.557e-3; 0; -0.031e5; 0]; Cp_2 = [5.457; 1.045e-3; 0; -1.157e5; 0];
Cp_3 = [1.702; 9.081e-3; -2.164e-6; 0; 0]; Cp_4 = [3.249; 0.422e-3; 0; 0.083e5; 0];
Cp_5 = [3.47; 1.45e-3; 0; 0.121e5; 0]; Cp_6 = [3.28; 0.593e-3; 0; 0.04e5; 0];
Cp_7 = [3.931; 1.49e-3; 0; -0.232e5; 0]; Cp_8 = [3.639; 0.506e-3; 0; -0.227e5; 0];
Cp = [Cp_1 Cp_2 Cp_3 Cp_4 Cp_5 Cp_6 Cp_7 Cp_8];
f_B = [1.0e-05;1.0e-05;1.0e-05;1.0e-05;128.4804;1.0e-05;1.0e-05;61.4471]
f_EG = [1.0e-05;1.0e-05;1.0e-05;1.0e-05;124.51957;1.0e-05;1.0e-05;59.5528]
T = [800;850];
f_Total = f_B + f_EG;
mole_frac = (f_Total)/sum(f_Total);
B_mole_frac = f_B/sum(f_B); EG_mole_frac = f_EG/sum(f_EG);
% Estimate species specific average Cp values in the bubble phase (J/mol/K)
for i = 1:length(Cp)
Avg_Cp_Bub(i,1) = (R/(T(1)- T_Ref))*(Cp(1,i)*(T(1)- T_Ref)+(1/2)*Cp(2,i)*(T(1)^2- T_Ref^2)+(1/3)*Cp(3,i)*(T(1)^3- T_Ref^3)-Cp(4,i)*(1/T(1)-1/T_Ref)+(1/4)*Cp(5,i)*(T(1)^4- T_Ref^4));
end
Avg_Cp_Bub_mix = sum(B_mole_frac.*Avg_Cp_Bub)
% Estimate average Cp values (J/mol/K) of the species corresponding to prevailing emulsion gas temperature
for i = 1:length(Cp)
Avg_Cp_EG(i,1) = (R/(T(2)- T_Ref))*(Cp(1,i)*(T(2)- T_Ref)+(1/2)*Cp(2,i)*(T(2)^2- T_Ref^2)+(1/3)*Cp(3,i)*(T(2)^3- T_Ref^3)-Cp(4,i)*(1/T(2)-1/T_Ref)+(1/4)*Cp(5,i)*(T(2)^4- T_Ref^4));
end
Avg_Cp_EG_mix = sum(EG_mole_frac.*Avg_Cp_EG)
T_mix_0 = 810;
T_mix = fzero(fun,T_mix_0)
function F = fun(x)
global R mole_frac Cp T_Ref Avg_Cp_Bub_mix Avg_Cp_EG_mix T f_B f_EG
Term1 = mole_frac(1,1)*(R./(x-T_Ref))*(Cp(1,1)*(x-T_Ref)+(1/2)*Cp(2,1)*(x^2-T_Ref^2)+(1/3)*Cp(3,1)*(x^3-T_Ref^3)-Cp(4,1)*(1/x-1/T_Ref)+(1/4)*Cp(5,1)*(x^4-T_Ref^4));
Term2 = mole_frac(2,1)*(R/(x-T_Ref))*(Cp(1,2)*(x-T_Ref)+(1/2)*Cp(2,2)*(x^2-T_Ref^2)+(1/3)*Cp(3,2)*(x^3-T_Ref^3)-Cp(4,2)*(1/x-1/T_Ref)+(1/4)*Cp(5,2)*(x^4-T_Ref^4));
Term3 = mole_frac(3,1)*(R/(x-T_Ref))*(Cp(1,3)*(x-T_Ref)+(1/2)*Cp(2,3)*(x^2-T_Ref^2)+(1/3)*Cp(3,3)*(x^3-T_Ref^3)-Cp(4,3)*(1/x-1/T_Ref)+(1/4)*Cp(5,3)*(x^4-T_Ref^4));
Term4 = mole_frac(4,1)*(R/(x-T_Ref))*(Cp(1,4)*(x-T_Ref)+(1/2)*Cp(2,4)*(x^2-T_Ref^2)+(1/3)*Cp(3,4)*(x^3-T_Ref^3)-Cp(4,4)*(1/x-1/T_Ref)+(1/4)*Cp(5,4)*(x^4-T_Ref^4));
Term5 = mole_frac(5,1)*(R/(x-T_Ref))*(Cp(1,5)*(x-T_Ref)+(1/2)*Cp(2,5)*(x^2-T_Ref^2)+(1/3)*Cp(3,5)*(x^3-T_Ref^3)-Cp(4,5)*(1/x-1/T_Ref)+(1/4)*Cp(5,5)*(x^4-T_Ref^4));
Term6 = mole_frac(6,1)*(R/(x-T_Ref))*(Cp(1,6)*(x-T_Ref)+(1/2)*Cp(2,6)*(x^2-T_Ref^2)+(1/3)*Cp(3,6)*(x^3-T_Ref^3)-Cp(4,6)*(1/x-1/T_Ref)+(1/4)*Cp(5,6)*(x^4-T_Ref^4));
Term7 = mole_frac(7,1)*(R/(x-T_Ref))*(Cp(1,7)*(x-T_Ref)+(1/2)*Cp(2,7)*(x^2-T_Ref^2)+(1/3)*Cp(3,7)*(x^3-T_Ref^3)-Cp(4,7)*(1/x-1/T_Ref)+(1/4)*Cp(5,7)*(x^4-T_Ref^4));
Term8 = mole_frac(8,1)*(R/(x-T_Ref))*(Cp(1,8)*(x-T_Ref)+(1/2)*Cp(2,8)*(x^2-T_Ref^2)+(1/3)*Cp(3,8)*(x^3-T_Ref^3)-Cp(4,8)*(1/x-1/T_Ref)+(1/4)*Cp(5,8)*(x^4-T_Ref^4));
Avg_Cp = (Term1 + Term2 + Term3 + Term4 + Term5 + Term6 + Term7 + Term8);
F = sum(f_B+f_EG)*(Avg_Cp)*(x - T_Ref) - (sum(f_B))*(Avg_Cp_Bub_mix)*(T(1)- T_Ref) - (sum(f_EG))*(Avg_Cp_EG_mix)*(T(2)- T_Ref);
end
Thanks in adavance!
Regards,
KD
  1 comentario
Dyuman Joshi
Dyuman Joshi el 15 de Abr. de 2022
You need to define your input function as an anonymous function.
You will also need to change the definition of other variables according.

Iniciar sesión para comentar.

Respuestas (1)

Alan Stevens
Alan Stevens el 15 de Abr. de 2022
Replace
T_mix = fzero(fun,T_mix_0);
by
T_mix = fzero(@fun,T_mix_0);
  1 comentario
Kareemulla Dudekula
Kareemulla Dudekula el 18 de Abr. de 2022
Thanks very much, Alan; this fixed the problem. I should have been more attetive to the prescribed syntax.

Iniciar sesión para comentar.

Categorías

Más información sobre Econometrics Toolbox en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by