Problème d'index Matlab
Répondre à la discussion
Affichage des résultats 1 à 2 sur 2

Problème d'index Matlab



  1. #1
    Dewo96

    Problème d'index Matlab


    ------

    Bonjour,

    Pour un cours de thermodynamique avancé, je dois utiliser Matlab (mais je n'ai pas l'habitude d'utiliser ce logiciel) 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);

    Code:
    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]');

    -----
    Dernière modification par Antoane ; 02/11/2020 à 21h49. Motif: Ajout balises code

  2. #2
    Antoane
    Responsable technique

    Re : Problème d'index Matlab

    Bonsoir et bienvenue sur futura,

    Je ne vois rien de bloquant dans le code mais on n'a pas accès à tout.

    Tu peux essayer de l'exécuter ligne à ligne et vérifier que tout correspond à ce que tu devrais trouver. En particulier, tu peux mettre un point d'arrêt sur la ligne 485 et vérifier avant de l'exécuter si T3max est comme attendu.

    Accessoirement, tu devrais pouvoir sortir certaines ligne de la boucle for j... :
    Code:
            T3 = T3max(i);
            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);
    HCH4r = cp_CH4*(Text - 273.15)- 74.6*(1/16); peut même complètement sortir des boucles.
    Deux pattes c'est une diode, trois pattes c'est un transistor, quatre pattes c'est une vache.

Discussions similaires

  1. (PHP) Problème Notice: Undefined index
    Par zanoloann dans le forum Programmation et langages, Algorithmique
    Réponses: 3
    Dernier message: 17/04/2019, 13h22
  2. [Thermique] problème température congélateur liebherr cnes 5056 index 20 g
    Par leon75 dans le forum Dépannage
    Réponses: 6
    Dernier message: 19/08/2018, 11h04
  3. [Matlab]Problème d'optimisation Abaqus/Matlab
    Par Saroute dans le forum Programmation et langages, Algorithmique
    Réponses: 3
    Dernier message: 08/04/2015, 17h54
  4. (PHP) Problème Notice: Undefined index
    Par ycouton dans le forum Programmation et langages, Algorithmique
    Réponses: 10
    Dernier message: 25/03/2014, 17h06
  5. [scilab] Problème sur une erreur d'index invalide
    Par invite42f97068 dans le forum Mathématiques du supérieur
    Réponses: 8
    Dernier message: 15/04/2010, 12h19