function DYDT=f(t,y)
% This is file conctank3.m
% INPUT: Time t and state vector y
% OUTPUT: derivatives DYDT
% Usage with ode15s:   [T,Y]=  ode15s('conctank3',[0 15],[0.9 0.9 0.9])

% I. Data (parameters and independent variables)
V1=5;     % volume tank 1
V2=1.5;   % volume tank 2
V3=1.5;   % volume tank 3
q=1;      % volumetric flowrate
tau1=V1/q; tau2=V2/q; tau3=V3/q; % residence times
cai=1;    % inlet concentration for t>0

% II. Extract present value of states
ca1=y(1); % concentration big tank 1
ca2=y(2); % concentration small tank 2
ca3=y(3); % concentration small tank 3

% III. Evaluate derivatives of states
f1= (cai - ca1)/tau1;
f2= (ca1 - ca2)/tau2;
f3= (ca2 - ca3)/tau3;
DYDT=[f1; f2; f3];

