How to loop on several inputs and variables?
Afficher commentaires plus anciens
I have written a program to calculate the molar flowrate, mass flowrate and mass fraction of the components at certain amount of ammonia produced per day. But I have to calculate for another 10 different amount of ammonia produced a day. I wish to use for loop to solve it but I have no idea on how to do it. Any suggestion on how to do this are much appreciated.
Below is my code.
clc
clear all
% Start
% Let M=mass flow rate, m=mass fraction, Y=molar flow rate
% Input variable
M= input('Enter the mass flow rate of ammonia produced in ton/day: ');
Eff=0.17
MW_NH3= 17
MW_N2= 28
MW_H2= 2
N2_to_NH3= 0.5
H2_to_N2= 3
% Molar flow rate calculation
% Calculation of the molar flow rate of N2 and H2 reacted,
M0 = M*1000; % to convert ton/day to kg/day
Y0=M0/MW_NH3; % to convert the mass flow rate of NH3 to molar flow rate
N2_reacted = Y0*(N2_to_NH3);
H2_reacted = (H2_to_N2)*N2_reacted;
% Calculation of the molar flow rate of N2 and H2 at reactor inlet
Y3= N2_reacted/Eff; % to calculate actual inlet of the N2 to the reactor
Y4= 3*Y3; % to calculate actual inlet of H2 to the reactor
% Calculation of molar flow rate of N2 and H2 at reactor outlet
Y1 = Y3 - N2_reacted; % N1 = unreacted N2
Y2 = Y4 - H2_reacted; % N2 = unreacted H2
% Mass flow rate calculation
% To calculate of mass flow rate of N2 and H2 at reactor outlet
M1 = Y1*(MW_N2); % mass flow rate of N2
M2 = Y2*(MW_H2); % mass flow rate of H2
% To calculate of mass flow rate of N2 and H2 at reactor inlet
M3 = Y3*(MW_N2); % mass flow rate of N2
M4 = Y4*(MW_H2); % mass flow rate of H2
% Mass fraction calculation
% To calculate the mass fraction at reactor outlet
m0 = M0/(M0+M1+M2); % mass fraction of NH3
m1 = M1/(M0+M1+M2); % mass fraction of N2
m2 = 1- m0 - m1; % mass fraction of H2
% To calculate the mass fraction at reactor inlet
m3 = M3/(M3+M4); % mass fraction of N2
m4 = 1- m3; % mass fraction of H2
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Data Type Conversion dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!