Problème index

Fermé
Dewo96 - Modifié le 2 nov. 2020 à 10:21
yg_be Messages postés 22696 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 17 avril 2024 - 2 nov. 2020 à 11:22
Bonjour,

Pour un cours de thermodynamique avancé, je dois utiliser Matlab pour un projet, j'ai codé cela mais j'ai le problème suivant : Index exceeds the number of array elements (4). Error in GT_final3 (line 485)
T3 = T3max(i);
Je ne comprends pas pourquoi puisque j'ai défini T3 avec 4 températures

Pourriez-vous m'aider s'il vous plaît ?

Error in GT_final3 (line 485)
T3 = T3max(i);

FIG(5) = figure;
r2 = linspace(2,50,50);
eta_cyclen = zeros(1,length(r2));
T3max = [1273.15 1473.15 1673.15 1873.15];
for i=1:4
for j=1:length(r2)
p2 = p1*r2(j);
T2 = fsolve(@(T2) T2 - T1*(r2(j))^(Ra*(T2-T1)/integral(cpa,T1,T2)*(1/eta_PiC)),600);
h2 = h1 + integral(cpa,T1,T2);
p3 = p2*k_cc;
T3 = T3max(i);
HO2r = integral(@(T) janaf2('c','O2',T),273.15,T2); % [J/kg.K]
HN2r = integral(@(T) janaf2('c','N2',T),273.15,T2);
HCH4r = cp_CH4*(Text - 273.15)- 74.6*(1/16);
HO2p = integral(@(T) janaf2('c','O2',T),273.15,T3);
HCO2p = integral(@(T) janaf2('c','CO2',T),273.15,T3) - 393.4/44; % enthalpy of formation the slides of the course [slide 5 of the part Energy and exergy performances of thermal power plants
HH2Op = integral(@(T) janaf2('c','H2O',T),273.15,T3) - 241.818/18; % enthalpy of formation
HN2p = integral(@(T) janaf2('c','N2',T),273.15,T3);

delta = @(Lam) HCH4r + 2*Lam*(HO2r*M(1) + a*HN2r*M(2)) + LHV*16 - HCO2p*44 - 2*HH2Op*18 - 2*(Lam-1)*HO2p*M(1) - 2*a*Lam*HN2p*M(2);
lambda = fsolve(delta,1); % we find the lambda that resolves our equation of enthalpy

M_gas = (1*44 + 2*18 + 2*(lambda-1)*32 + 2*a*lambda*28) ; %mass of the product gas
x_CO2 = 1*44/M_gas; % mass fraction C02
x_H2O = 2*18/M_gas; % mass fraction H2O
x_O2 = 2*(lambda-1)*32/M_gas; % mass fraction O2
x_N2 = 2*a*lambda*28/M_gas; % mass fraction N2

cpf = (@(T) x_CO2*janaf2('c','CO2',T) + x_H2O*janaf2('c','H2O',T) + x_O2*janaf2('c','O2',T) + x_N2*janaf2('c','N2',T)); % this is something you do in part 4 I think with cpf
cpfs = (@(T) (x_CO2*janaf2('c','CO2',T) + x_H2O*janaf2('c','H2O',T) + x_O2*janaf2('c','O2',T) + x_N2*janaf2('c','N2',T))./T);% and cpfs

Tot = 1 + 2 + 2*(lambda-1) + 2*a*lambda;
n_CO2 = 1/Tot; % molar fraction of CO2
n_H2O = 2/Tot; % molar fraction of H2O
n_O2 = 2*(lambda-1)/Tot; % molar fraction of O2
n_N2 = 2*a*lambda/Tot; % molar fraction of N2

Rf = r2/(44*n_CO2+18*n_H2O+32*n_O2+28*n_N2); % [kJ/kg.K]
h3 =(LHV + lambda*ma1*h2R)/(1 + lambda*ma1);
s3 = s2R + integral(cpfs,T2R,T3max) - Rf*log(p3/p2);
e3 = (h3 - h1) - T0*(s3 - s1);
eta_cyclen(j) = ((1 + 1/(lambda*ma1))*(h3-h4)-(h2-h1))/((1 + 1/(lambda*ma1))*h3-h2);

end
%plot
hold on
plot(r2,eta_cyclen)
xlabel('r : Pressure ratio');
ylabel('eta_{cyclen}')
grid on;
end
legend('T3 = 1000 [°C]','T3 = 1200 [°C]','T3 = 1400 [°C]','T3 = 1600 [°C]');

1 réponse

yg_be Messages postés 22696 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 17 avril 2024 1 471
2 nov. 2020 à 11:22
bonjour,
dans ce cas, pour investiguer, il est utile de simplifier le programme. soit pour découvrir l'erreur, soit pour permettre la suite de l'analyse.
as-tu testé ceci?
T3max = [1273.15 1473.15 1673.15 1873.15];
for i=1:4
T3 = T3max(i);
end
0