function dTgasdt = elheater(t,X,U)

% This function is called by the s-function elheaters.m and calculates the
% derivative of the temperature of the gas leaving the electric heater.

% The parameters are given in "parameters.m".
 
global par

% Collecting parameters
P       =   par.P;
M       =   par.M;
R       =   par.R;
Velh    =   par.Velh;
cpg     =   par.cpg;
cpel    =   par.cpel;
cpelw   =   par.cpelw;
mel     =   par.mel;
melw    =   par.melw;
UAel    =   par.UAel;
UAelw   =   par.UAelw;



% Inputs and disturbances
T0      =   U(1);                     % Inlet temperature [C]
W       =   U(2);                     % Effect to gas from elheater [W]
m       =   U(3);                     % Mass flow of process gas [kg/s]
mair    =   U(4);                     % Mass flow of air [kg/s]

% Defining the states
Tgas = X;                                % Temp. of gas leaving elheater [C]



%%%%%%%%%%%%%%%   Calculation of state derivative   %%%%%%%%%%%%%%%%%%%%%%%

dTgasdt  =  (T0-Tgas)*((m+mair)*R*(Tgas+273.15)/(P*M*Velh)) +  W*(R*(Tgas+273.15)/(P*M*Velh*cpg));


% dTgasdt  =  0;
% 
% dTeldt   =  0;
% 
% dTelwdt  = 0;



end

