Speed Programming in Matlab/Octave for non computer science engineers(Stociometric coefficient)
The code is to calculate the value of the stoichiometric coefficients of the equation:
CnH2n+2 + ar( O2 + 3.76N2 ) = aCO2 + bH2O + cN2
close all
clear all
clc
%chemical equation CnH2n+2 + ar(O2 + 3.76*N2)= a*CO2 + b*H2O + c*N2
%number of moles of carbon atom in 1 mole of fuel(alkane, alkene, alkyne)
%case x=1 has been excluded because for alkene and alkyne, atleast 2 carbon atoms are required
x=2:15
%number of moles of carbon dioxide = moles of carbon atom in 1 mole of fuel
a=x
%number of moles of hydrogen atoms in each type of fuel :-
[h_alkane h_alkene h_alkyne] = stocio_coeff(x);
%number of moles of H2O molecule in each type of fuel :-
b_alkane= h_alkane*0.5
b_alkene= h_alkene*0.5
b_alkyne= h_alkyne*0.5
%number of moles of O2 molecule in each type of fuel:-
ar_alkane= x+0.25*h_alkane
ar_alkene= x+0.25*h_alkene
ar_alkyne= x+0.25*h_alkyne
%number of moles of N2 molecule:-
c_alkane=3.76*ar_alkane
c_alkene=3.76*ar_alkene
c_alkyne=3.76*ar_alkyne
%graph between moles of carbon atom(x) and stociometric coefficient 'ar'
plot(x,ar_alkane,'r','linewidth',2)
hold
plot(x,ar_alkene,'b','linewidth',2)
plot(x,ar_alkyne,'g','linewidth',2)
title('number of carbon atoms vs stociometric coefficient ar')
xlabel('number of atoms of carbon')
ylabel('stociometric coefficient ar')
legend('Alkane', 'alkene', 'alkyne')
To calculate the coefficients, a function, stocio_coeff(n), has been defined which calculates the number of hydrogen atoms in the fuel according to the type of fuel such as alkane, alkene, and alkyne.
function [y1 y2 y3]= stocio_coeff(n)
y1 = 2*n + 2;
y2 = 2*n;
y3 = 2*n - 2;
end
1. Here we can see that each type of fuel has a number of variations according to the number of carbon atoms. So in the first step, the number of carbon atoms is selected from 2-15.
2. The case of one carbon atom is excluded because for alkene and alkyne, at least 2 carbon atoms are required.
3. In Line 14, the function is called and the three outputs are the number of hydrogen atoms in the fuel.
4. With the help of Hydrogen atoms, the value of a, b, and ar are calculated.
5. After calculating ar, the value of c is calculated.
6. After that a graph has to be plotted between n and ar for each fuel in the same graph. To do so, the command Hold is used.
The output of the code is: