function pr1fct=dy_dw(w,y)

% Initial pressure (atm)
P_0=1;
% Initial temperature for the system (K)
T_i=873;
% Total flow rate (mol/s)
FT=y(1)+y(2)+y(3)+y(4)+y(5)+y(6);

F0_CH4=y(1);

% Change in total flow rate, (atm s/mol)
FT_change=P_0/FT;
% Change in partial pressures, (atm)
P_CH4=FT_change*y(1);
P_CO2=FT_change*y(2);
P_H2=FT_change*y(3);
P_H2O=FT_change*y(4);
P_CO=FT_change*y(5);
P_N2=FT_change*y(6);

% y(1)-y(6) represents the flow rates of the species, (mol/s)
 
% Universal gas constant, (J/mol K)
R=8.3144621;

%Parameters for reaction rate
k1L=1292*exp(-12894/y(7)); % (gmol/gcat s atm)
k7L=(3.8*2.71828)-(3*exp(-220/y(7))); %(gmol/gcat s)
Ka=7.4*exp(-4145/y(7)); %(atm^-2)
Kb=2.3*2.71828*exp(-15998/y(7));%(atm^-2.5)
c=5.8*exp(8605/y(7));%(-)

%Reaction Rate CH4, (gmol/gcat s)
if P_CO2 < 0.75
    r_CH4=(k1L*P_CH4)/(((k1L*P_CH4*P_CO)/(k7L*Ka*P_CO2))+((Kb*P_CO2*P_H2^0.5)/P_CO)+((k1L*P_CH4)/k7L)+1);
else 
    r_CH4=c*k1L*P_CH4;
end

%Reaction rate CO2, (gmol/gcat s)
r_CO2 = 2*r_CH4;
%Reaction rate H2, (gmol/gcat s)
r_H2 = -r_CH4;
%Reaction rate H2O, (gmol/gcat s)
r_H2O= -r_CH4;
%Reaction rate CO, (gmol/gcat s)
r_CO=-3*r_CH4;

%Conversion from calories to joule
cal_to_joule=4.184;
% Heat capacity constants, (J/gmol °C)
CH4=[3.381 18.044E3 -4.300e6]/cal_to_joule;
CO2=[6.214 10.396E3 -3.545E6]/cal_to_joule;
H2=[6.945 -0.200E3 0.481E6]/cal_to_joule;
H2O=[7.256 2.298E3 0.283E6]/cal_to_joule;
CO=[6.420 1.665E3 -0.196E6]/cal_to_joule;
N2=[6.524 1.250E3 -0.001E6]/cal_to_joule;
 
% Heat capacity constants multiplied by flow rates, (J /s °C)
delta_A=(y(1)*CH4(1))+(y(2)*CO2(1))+(y(3)*H2(1))+(y(4)*H2O(1))+(y(5)*CO(1))+(y(6)* N2(1));
delta_B=(y(1)*CH4(2))+(y(2)*CO2(2))+(y(3)*H2(2))+(y(4)*H2O(2))+(y(5)*CO(2))+(y(6)* N2(2));
delta_C=(y(1)*CH4(3))+(y(2)*CO2(3))+(y(3)*H2(3))+(y(4)*H2O(3))+(y(5)*CO(3))+(y(6)* N2(3));

Cp =R*(delta_A+delta_B*y(7)+delta_C*y(7)^2); 

%Heats of formation at 298 K,(J/mol)
Hf_CH4=-74520;
Hf_CO2=-393509;
Hf_H2=0;
Hf_H2O=-241818;
Hf_CO=-110525;

% Enthalpy of reaction at 298 K, (J/mol)
delta_Hrxn=(Hf_H2+Hf_H2O+3*Hf_CO)-(Hf_CH4+2*Hf_CO2);

% Reference temperature, (K)
T0=298;
% For initial system temperature to reference temperature
Tau_i=T_i/T0;
% For temperature at some catalyst weight to reference temperature
Tau_f=y(7)/T0;
 
% Constant change for reaction
delta_constants=H2+H2O+3*CO-2*CO2-CH4;
% Initial enthalpy change from initial system temperature to reference temperature
delta_Hinitial=delta_constants(1)*T0*(Tau_i-1)+(delta_constants(2)/2)*(T0^2)*((Tau_i^2)-1)+(delta_constants(3)/3)*(T0^3)*((Tau_i^3)-1);
% Final enthalpy change from reference temperature to the temperature at some catalyst weight
delta_Hfinal=delta_constants(1)*T0*(Tau_f-1)+(delta_constants(2)/2)*(T0^2)*((Tau_f^2)-1)+(delta_constants(3)/3)*(T0^3)*((Tau_f^3)-1);
% Enthalpy change in the system for reaction
delta_H=delta_Hrxn+R*delta_Hfinal+R*delta_Hinitial;


dy_dw=zeros(8,1);
 
dy_dw(1)=r_CH4; %CH4
dy_dw(2)=r_CO2; %CO2
dy_dw(3)=r_H2; %H2
dy_dw(4)=r_H2O; %H2O
dy_dw(5)=r_CO; %CO
dy_dw(7)=((-delta_H)*r_CH4)/(Cp); %T
dy_dw(8)=(y(1)-F0_CH4)/F0_CH4; % X_CH4
end
