Cannot get integral function to work for two limits

1 visualizzazione (ultimi 30 giorni)
Andrew
Andrew il 26 Mag 2023
Risposto: Alan Stevens il 26 Mag 2023
I have written a script to determine total energy out of a system.
The energy equation does not work when I attempt to use an interal function for two temperatures.
I have attached the script, from lines 82 to 122 containes the issues I am having.
I am attempting to use the equation C1 + C2*((C3/T)/(sinh(C3/T))^2)+C4*((C5/T_4)/(cosh(C5/T_4))^2 to calculate the specific heat capacity.
Where C1-C5 are given.
The T variable is the integral between two limits.
This calculation of the specific heat capacity is need to be done 6 times.
I have tried setting all the C values to values with different numbers e.g C11-C15 and then the next component to C21-C25.
With every alteration i get this same result.
Any help would be much appreciated
Undefined function 'function_Cp_1' for input arguments of type 'double'.
Error in integralCalc/iterateScalarValued (line 314)
fx = FUN(t);
Error in integralCalc/vadapt (line 132)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen);
Error in integralCalc (line 75)
[q,errbnd] = vadapt(@AtoBInvTransform,interval);
Error in integral (line 87)
Q = integralCalc(fun,a,b,opstruct);
Error in Matlab_Assignment_2 (line 90)
Cp_C4H6O2_i=integral(@function_Cp_1,Ti,T1);
%Enthalpy datum conditions (Kelvin)
Ti=(25+273.15);
%Input temperature (Kelvin)
T1=(183+273.15);
%Output temperatre (Kelvin)
T2=(Exit_temperature_degrees_Celcius+273.15);
%Specific heat capacity of C4H6O2 (J/kmol K)
C1=85298;
C2=135600;
C3=826.44;
C4=72341;
C5=2548.6;
function_Cp_1=@(T_1) (C1+(C2*((C3/T_1)/(sinh(C3/T_1)))^2)+(C4*((C5/T_1)/(cosh(C5/T_1)))^2));
Cp_C4H6O2_i=integral(@function_Cp_1,Ti,T1);
Cp_C4H6O2_f=integral(@function_Cp_1,Ti,T2);
%Specific heat capacity of O2 (J/kmol K)
C1=29103;
C2=10040;
C3=2526.5;
C4=9356.0;
C5=1153.8;
function_Cp_2=@(T_2) (C1+(C2*((C3/T_2)/(sinh(C3/T_2)))^2)+(C4*((C5/T_2)/(cosh(C5/T_2)))^2));
Cp_O2_i=integral(@function_Cp_2,Ti,T1);
Cp_O2_f=integral(@function_Cp_2,Ti,T2);
%Specific heat capacity of CO2 (J/kmol K)
C1=29370;
C2=34540;
C3=1428.0;
C4=26400;
C5=588.0;
function_Cp_3=@(T_3) (C1+(C2*((C3/T_3)/(sinh(C3/T_3))^2)+(C4*((C5/T_3)/(cosh(C5/T_3)))^2)));
Cp_CO2=integral(@function_Cp_3,Ti,T1);
%Specific heat capcaity of H2O (J/kmol K)
C1=33363;
C2=26790;
C3=2610.5;
C4=8896.0;
C5=1169.0;
function_Cp_4=@(T_4) (C1+(C2*((C3/T_4)/(sinh(C3/T_4))^2)+(C4*((C5/T_4)/(cosh(C5/T_4)))^2)));
Cp_H2O=integral(@function_Cp_4,Ti,T2);
Undefined function 'function_Cp_1' for input arguments of type 'double'.
Error in integralCalc/iterateScalarValued (line 314)
fx = FUN(t);
Error in integralCalc/vadapt (line 132)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen);
Error in integralCalc (line 75)
[q,errbnd] = vadapt(@AtoBInvTransform,interval);
Error in integral (line 87)
Q = integralCalc(fun,a,b,opstruct);
Error in Matlab_Assignment_2 (line 90)
Cp_C4H6O2_i=integral(@function_Cp_1,Ti,T1);
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.

Risposte (1)

Alan Stevens
Alan Stevens il 26 Mag 2023
Try this
%Enthalpy datum conditions (Kelvin)
Ti=(25+273.15);
%Input temperature (Kelvin)
T1=(183+273.15);
%Output temperatre (Kelvin)
Exit_temperature_degrees_Celcius = 100; % Arbitrary value
T2=(Exit_temperature_degrees_Celcius+273.15);
%Specific heat capacity of C4H6O2 (J/kmol K)
C1=85298;
C2=135600;
C3=826.44;
C4=72341;
C5=2548.6;
% Note the .* and ./ in the following line
function_Cp_1=@(T_1) (C1+(C2*((C3./T_1)./(sinh(C3./T_1))).^2)+(C4*((C5./T_1)./(cosh(C5./T_1))).^2));
Cp_C4H6O2_i=integral(function_Cp_1,Ti,T1); % No need for @ here with in-line function
Cp_C4H6O2_f=integral(function_Cp_1,Ti,T2); % ditto
disp([Cp_C4H6O2_i, Cp_C4H6O2_f])
1.0e+07 * 1.8748 0.8221

Categorie

Scopri di più su Matrix Computations in Help Center e File Exchange

Prodotti


Release

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by