% Exercise 2
% [Ri,Ro,d]
v = [input('Please input a rate at which water enters the cistern: '),input('Please input a rate at which water exits the cistern: '), input('Please enter an initial water level: ')];
[time, depth, t] = overflowEmpty(v);
fprintf('The cistern takes %i minutes to empty/overflow',t)
figure(1)
plot(time,depth,'b-*')
title('Depth of Water in Tank')
xlabel('Time (m)')
ylabel('Depth(ft)')
and then
function [time,depth,t]= overflowEmpty(v)
H=24; %initial Height
t = 0; % Time = initialized to 1
d = v(3); % Depth = starting depth
while 0<d<H
d = (v(1)-v(2))*t+v(3); %D