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 visualizzazioni (ultimi 30 giorni)
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

Risposte (1)

VBBV
VBBV il 5 Mar 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
H_water = -2.4205e+05
H_water = -2.4037e+05
H_water = -2.3866e+05
H_water = -2.3694e+05
H_water = -2.3519e+05
H_water = -2.3342e+05
H_water = -2.3162e+05
H_water = -2.2979e+05
H_water = -2.2793e+05
H_water = -2.2604e+05
H_water = -2.2412e+05
H_water = -2.2217e+05
H_water = -2.2019e+05
H_water = -2.1818e+05
H_water = -2.1613e+05

Categorie

Scopri di più su Particle & Nuclear Physics in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by