Inf or NaN whilst trying to run a function
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi, I'm very new to MATLAB and I am having some trouble. I'm trying to integrate an equation to solve for specific heat capacity. Could somebody please explain what this error is and how to fix it? Thanks.
T_datum_K = 25+273.15;
T_in_K = 199.3 + 273.15;
T_out_K = 359 + 273.15;
%Ar
C1_Ar = 20786;
C2_Ar = 0;
C3_Ar = 0;
C4_Ar = 0;
C5_Ar = 0;
func = @(T) C1_Ar + C2_Ar.*((C3_Ar./T)./(sinh(C3_Ar./T))).^2 + C4_Ar.*((C5_Ar./T)./(cosh(C5_Ar./T))).^2;
Cp_Ar_in = integral(func, T_datum_K, T_in_K);
Cp_Ar_out = integral(func, T_datum_K, T_out_K);
0 Commenti
Risposte (1)
VBBV
il 23 Mag 2023
Modificato: VBBV
il 23 Mag 2023
T_datum_K = 25+273.15;
T_in_K = 199.3 + 273.15;
T_out_K = 359 + 273.15;
%Ar
C1_Ar = 20786;
C2_Ar = 1;
C3_Ar = 0.1;
C4_Ar = 0.1;
C5_Ar = 0.1;
func = @(T) C1_Ar + C2_Ar.*((C3_Ar./T)./(sinh(C3_Ar./T))).^2 + C4_Ar.*((C5_Ar./T)./(cosh(C5_Ar./T))).^2;
Cp_Ar_in = integral(func, T_datum_K, T_in_K)
Cp_Ar_out = integral(func, T_datum_K, T_out_K)
3 Commenti
Walter Roberson
il 23 Mag 2023
T_datum_K = 25+273.15;
T_in_K = 199.3 + 273.15;
T_out_K = 359 + 273.15;
%Ar
C1_Ar = 20786;
syms C2_Ar C3_Ar C4_Ar C5_Ar T real
func = @(T) C1_Ar + C2_Ar.*((C3_Ar./T)./(sinh(C3_Ar./T))).^2 + C4_Ar.*((C5_Ar./T)./(cosh(C5_Ar./T))).^2;
Cp_Ar_in = int(func, T, T_datum_K, T_in_K)
Notice the exp(40*C3_Ar/5963) - 1 in the denominator. As C3_Ar approaches 0, the exp() approaches 1, and subtracting 1 from that approaches 0, leading to a division by 0 if you are operating numerically. But there is also a C3_Ar^2 in the numerator and that can "cancel" the division, if you operate symbolically on the limit
limit(Cp_Ar_in, C3_Ar, 0)
As C5_Ar approaches 0, the C5_Ar multiple of the terms approaches 0 so you get divisions by 0 there, with two such divisions with slightly different fractions being subtracted. But the whole thing is being multiplied by C5_Ar^2 so again you get some canceling in the limit:
limit(ans, C5_Ar, 0)
Therefore, if you are careful to operate in the limit case, C3_Ar == 0 and C5_Ar == 0 can be accounted for. But not if you operate neively with integral()
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!