% Function to compute rates of change of demand and supply functions
%
% two state variables in the system
% p(1) = L(t) = L(t-1) + [demand(t) - supply(t)] (dt)	% queue length 
% p(2) = A(t) = A(t-1) + [L(t)] (dt)					% area under L(t) curve

function pprime = fqueue_2(t,p)

global demand capacity time


% Define the rate equations

demand_table 	= interp1(time,demand,t);
capacity_table 	= capacity;

if (demand_table < capacity_table) & (p(1) > 0)
	pprime(1) = demand_table - capacity_table;	% rate of change in state variable
elseif demand_table > capacity_table
	pprime(1) = demand_table - capacity_table;	% rate of change in state variable
else
	pprime(1) = 0.0;				% avoids accumulation of entities if queue length is zero
end

pprime(2) = p(1);					% integrates the delay curve over time
pprime = pprime';
