Function
Function
clear all
clc
h = 0.1;
sc = 15;
n = sc/h;
h1(1) = 4.5;
h2(1) = 4;
t(1)= 0;
for i = 1:n
t(i+1) = t(i)+h;
p1=h*nonint1(t(i),h1(i));
p2=h*nonint1(t(i)+(h/2),h1(i)+(p1/2));
p3=h*nonint1(t(i)+(h/2),h1(i)+(p2/2));
p4=h*nonint1(t(i)+h,h1(i));
h1(i+1)=h1(i)+((p1+(2*p2)+(2*p3)+p4)/6);
m1=h*nonint2(t(i),h1(i),h2(i));
m2=h*nonint2(t(i)+(h/2),h1(i)+(p1/2),h2(i)+(m1/2));
m3=h*nonint2(t(i)+(h/2),h1(i)+(p2/2),h2(i)+(m2/2));
m4=h*nonint2(t(i)+h,h1(i)+p3,h2(i)+m3);
h2(i+1)=h2(i)+((m1+(2*m2)+(2*m3)+m4)/6);
end
disp(' Time,min Height 1,ft Height 2,ft ')
disp([t;h1;h2]')
subplot(2,1,1);plot(t,h1);
title('Variation of the liquid levels w.r.t time in the two tanks non
interacting system using Runge Kutta method')
xlabel('Time,min')
ylabel('Height 1,ft')
subplot(2,1,2);plot(t,h2);
xlabel('Time,min')
ylabel('Height 2,ft')
function adot = nonint1(t,h1)
q = 5;
r1 = 1;
q1 = (h1)/r1;
dh1dt = q-q1;
adot =[dh1dt];
function cdot = nonint2(t,h1,h2)
r1 = 1;
q1 = (h1)/r1;
r2 = 1;
q2 = (h2/r2);
dh2dt = q1-q2;
cdot = [dh2dt];
Time,min Height 1,ft Height 2,ft
0 4.5000 4.0000
>>