I wrote a piece of code about Calculating the Enthalpy of H2, O2, and Water and the machine reports the error "Array indices must be positive integers or logical values".
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
R = 8.314; % Ideal Gas Constant
T = 300 : 50 : 1000; % Temperature range from 300 K to 1000 K with increments of 50
% Create Temperature Loop
I = 0; % Initialization of loop variable
for T = 300 : 50 : 1000; % Temperature range from 300 K to 1200 K with increments of 50
I = I + 1; % Loop variable
% Hydrogen enthalpy calculations
hf_h = 0; % Hydrogen enthalpy at the standard state
hs_h = R*(((3.057 * T) + ((1/2) * 2.677E-3 * T^2) - ((1/3) * 5.810E-6 * T^3) + ((1/4) * 5.521E-9 * T^4) - ((1/5) * 1.812E-12 * T^5)) - (3.057 * 298 + ((1/2) * 2.677E-3 * 298^2) - ((1/3) * 5.810E-6 * 298^3) + ((1/4) * 5.521E-9 * 298^4) - ((1/5) * 1.812E-12 * 298^5)));
H_hydrogen = (hf_h + hs_h); % Enthalpy of Hydrogen
hf_o = 0; % Oxygen enthalpy at the standard state
hs_o = R * (((3.626 * T) - ((1/2) * 1.878E-3 * T^2) + ((1/3) * 7.055E-6 * T^3) - ((1/4) * 6.764E-9 * T^4) + ((1/5) * 2.156E-12 * T^5)) - (3.626 * 298 - ((1/2) * 1.878E-3 * 298^2) + ((1/3) * 7.055E-6 * 298^3) - ((1/4) * 6.764E-9 * 298^4) + ((1/5) * 2.156E-12 * 298^5)));
H_oxygen = (hf_o + hs_o); % Enthalpy of Oxygen
% Water enthalpy calculations
hf_w = -241820; % Water enthalpy at the standard state
hs_w = R * (((4.070 * T) - ((1/2) * 1.108E-3 * T^2) + ((1/3) * 4.152E-6 * T^3) - ((1/4) * 2.964E-9 * T^4) + ((1/5) * 0.807E-12 * T^5)) - (4.070 * 298) - ((1/2) * 1.108E-3 * 298^2) + ((1/3) * 4.152E-6 * 298^3) - ((1/4) * 2.964E-9 * 298^4) + ((1/5) * 0.807E-12 * 298^5));
H_water = (hf_w + hs_w) % Enthalpy of Water
% Create new variables to save the new calculated values for hydrogen, oxygen, and water enthalpy at each temperature increment
Hydrogen_Enthalpy(i) = H_hydrogen;
Oxygen_Enthalpy(i) = H_oxygen;
Water_Enthalpy(i) = H_water;
Temperature(i) = T;
end % End Loop
1 comentario
Respuestas (1)
VBBV
el 5 de Mzo. de 2024
R = 8.314; % Ideal Gas Constant
T = 300 : 50 : 1000; % Temperature range from 300 K to 1000 K with increments of 50
% Create Temperature Loop
I = 0; % Initialization of loop variable
for T = 300 : 50 : 1000; % Temperature range from 300 K to 1200 K with increments of 50
I = I + 1; % Loop variable
% Hydrogen enthalpy calculations
hf_h = 0; % Hydrogen enthalpy at the standard state
hs_h = R*(((3.057 * T) + ((1/2) * 2.677E-3 * T^2) - ((1/3) * 5.810E-6 * T^3) + ((1/4) * 5.521E-9 * T^4) - ((1/5) * 1.812E-12 * T^5)) - (3.057 * 298 + ((1/2) * 2.677E-3 * 298^2) - ((1/3) * 5.810E-6 * 298^3) + ((1/4) * 5.521E-9 * 298^4) - ((1/5) * 1.812E-12 * 298^5)));
H_hydrogen = (hf_h + hs_h); % Enthalpy of Hydrogen
hf_o = 0; % Oxygen enthalpy at the standard state
hs_o = R * (((3.626 * T) - ((1/2) * 1.878E-3 * T^2) + ((1/3) * 7.055E-6 * T^3) - ((1/4) * 6.764E-9 * T^4) + ((1/5) * 2.156E-12 * T^5)) - (3.626 * 298 - ((1/2) * 1.878E-3 * 298^2) + ((1/3) * 7.055E-6 * 298^3) - ((1/4) * 6.764E-9 * 298^4) + ((1/5) * 2.156E-12 * 298^5)));
H_oxygen = (hf_o + hs_o); % Enthalpy of Oxygen
% Water enthalpy calculations
hf_w = -241820; % Water enthalpy at the standard state
hs_w = R * (((4.070 * T) - ((1/2) * 1.108E-3 * T^2) + ((1/3) * 4.152E-6 * T^3) - ((1/4) * 2.964E-9 * T^4) + ((1/5) * 0.807E-12 * T^5)) - (4.070 * 298) - ((1/2) * 1.108E-3 * 298^2) + ((1/3) * 4.152E-6 * 298^3) - ((1/4) * 2.964E-9 * 298^4) + ((1/5) * 0.807E-12 * 298^5));
H_water = (hf_w + hs_w) % Enthalpy of Water
% Create new variables to save the new calculated values for hydrogen, oxygen, and water enthalpy at each temperature increment
Hydrogen_Enthalpy(I) = H_hydrogen;
Oxygen_Enthalpy(I) = H_oxygen;
Water_Enthalpy(I) = H_water;
Temperature(I) = T;
end % End Loop
1 comentario
Ver también
Categorías
Más información sobre Particle & Nuclear Physics en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!