You are on page 1of 19

Problem No: Name: Jagadeesh Caszo.

Date: Roll No: 21021A0849.


EULER METHOD

Problem Statement:

For the initial value problem, 𝑦 ′ + 2𝑦 = 2 − 𝑒 −4𝑡 , y(0)=1 using Euler Method with the step
size of h=0.1 to find appropriate values of the solution at t=0.1, 0.2, 0.3.

MATLAB Code: stepsize848.m


clc
clear all
h=0.1; % step size of the function%
y(1)=1; % initial value of y%
x=[0;0.1;0.2;0.3]; % time in min%
fprintf(' x(time) y\n') % printing results%
for i=1:4; % calculating loop%
dydx(i)=(2-(exp(-(4*x(i))))-(2*y(i))); % differential equation%
y(i+1)=y(i)+(dydx(i)*h); % Euler equation%
disp([x(i)' y(i)']) % display command%
end
Output:
x(time) y
0 1
0.1000 0.9000
0.2000 0.8530
0.3000 0.8374
Report:
The given differential equation is solved for the values of y at given t using eulers method in
MATLAB.
Problem No: Name: Jagadeesh Caszo.
Date: Roll No: 21021A0849.
RUNGE-KUTTA 4th ORDER METHOD

Problem Statement:

Solve 𝑓(𝑥, 𝑦) = 𝑥𝑦, 𝑥0 = 1, 𝑦0 = 2, ℎ = 0.1 upto 3 Iterations using RK 4th Order method.

MATLAB Code: rk848.m


clc
clear all
h=0.1; % step size of the function%
x(1)=1; % initial value of x%
y(1)=2; % initial value of y%
fprintf(' x y\n') % printing results%
for i=1:4 % calculating loop%
x(i+1)=h+x(i); % no. of iterations%
k1=h*x(i)*y(i); % R-K parameter%
k2=h*((x(i)+(h/2))*(y(i)+(k1/2))); % R-K parameter%
k3=h*((x(i)+(h/2))*(y(i)+(k2/2))); % R-K parameter%
k4=h*((x(i)+(h/2))*(y(i)+k3)); % R-K parameter%
y(i+1)=y(i)+((1/6)*(k1+(2*k2)+(2*k3)+k4)); % R-K forth order equation%
disp([x(i) y(i)']) % display command%
end
Output:
x y
1 2
1.1000 2.2196
1.2000 2.4880
1.3000 2.8169
Report:
The given differential equation is solved using Runge-Kutta 4th order method and solutions are
obtained as x=1.0, 1.1, 1.2, 1.3. y values are 2.0, 2.2196, 2.4880, 2.8169.
Problem No: Name: Jagadeesh Caszo.
Date: Roll No: 21021A0849.
TWO TANK NON- INTERACTING SYSTEM

Problem Statement:
Consider the following set of differential equations that describe two tank liquid level non-
interacting system.
𝑑ℎ1 ℎ1
= 𝑞 − 𝑞1 𝑤ℎ𝑒𝑟𝑒 𝑞1 =
𝑑𝑡 𝑅1
𝑑ℎ2 ℎ2
= 𝑞1 − 𝑞2 𝑤ℎ𝑒𝑟𝑒 𝑞2 =
𝑑𝑡 𝑅2
𝑓𝑡 3 𝑓𝑡
The Parameter values are q=5 𝑚𝑖𝑛 , 𝑅1 = 1 𝑐𝑓𝑚 , 𝑡 = 0 𝑡𝑜 15 𝑚𝑖𝑛. Increments is 0.1; h1=1 ft,
h2=2 ft.

Fig: two tank liquid level system


Output:
time h1 in ft h2 in ft time h1 in ft h2 in ft
0 1 2 3.1000 4.8474 4.3599
0.1000 1.4000 1.9000 3.2000 4.8627 4.4086
0.2000 1.7600 1.8500 3.3000 4.8764 4.4540
0.3000 2.0840 1.8410 3.4000 4.8887 4.4963
0.4000 2.3756 1.8653 3.5000 4.8999 4.5355
0.5000 2.6380 1.9163 3.6000 4.9099 4.5720
0.6000 2.8742 1.9885 3.7000 4.9189 4.6058
0.7000 3.0868 2.0771 3.8000 4.9270 4.6371
0.8000 3.2781 2.1780 3.9000 4.9343 4.6661
0.9000 3.4503 2.2881 4.0000 4.9409 4.6929
1.0000 3.6053 2.4043 4.1000 4.9468 4.7177
1.1000 3.7448 2.5244 4.2000 4.9521 4.7406
1.2000 3.8703 2.6464 4.3000 4.9569 4.7617
1.3000 3.9833 2.7688 4.4000 4.9612 4.7813
1.4000 4.0849 2.8903 4.5000 4.9651 4.7993
1.5000 4.1764 3.0097 4.6000 4.9686 4.8158
1.6000 4.2588 3.1264 4.7000 4.9717 4.8311
1.7000 4.3329 3.2396 4.8000 4.9745 4.8452
1.8000 4.3996 3.3490 4.9000 4.9771 4.8581
1.9000 4.4597 3.4540 5.0000 4.9794 4.8700
2.0000 4.5137 3.5546 5.1000 4.9814 4.8809
2.1000 4.5623 3.6505 5.2000 4.9833 4.8910
2.2000 4.6061 3.7417 5.3000 4.9850 4.9002
2.3000 4.6455 3.8281 5.4000 4.9865 4.9087
2.4000 4.6809 3.9099 5.5000 4.9878 4.9165
2.5000 4.7128 3.9870 5.6000 4.9890 4.9236
2.6000 4.7416 4.0596 5.7000 4.9901 4.9302
2.7000 4.7674 4.1278 5.8000 4.9911 4.9362
2.8000 4.7907 4.1917 5.9000 4.9920 4.9417
2.9000 4.8116 4.2516 6.0000 4.9928 4.9467
3.0000 4.8304 4.3076 6.1000 4.9935 4.9513
6.2000 4.9942 4.9555 9.5000 4.9998 4.9980
6.3000 4.9948 4.9594 9.6000 4.9998 4.9982
6.4000 4.9953 4.9629 9.7000 4.9999 4.9983
6.5000 4.9958 4.9662 9.8000 4.9999 4.9985
6.6000 4.9962 4.9691 9.9000 4.9999 4.9986
6.7000 4.9966 4.9718 10.0000 4.9999 4.9987
6.8000 4.9969 4.9743 10.1000 4.9999 4.9989
6.9000 4.9972 4.9766 10.2000 4.9999 4.9990
7.0000 4.9975 4.9786 10.3000 4.9999 4.9991
7.1000 4.9977 4.9805 10.4000 4.9999 4.9991
7.2000 4.9980 4.9822 10.5000 4.9999 4.9992
7.3000 4.9982 4.9838 10.6000 4.9999 4.9993
7.4000 4.9984 4.9852 10.7000 4.9999 4.9994
7.5000 4.9985 4.9866 10.8000 5.0000 4.9994
7.6000 4.9987 4.9878 10.9000 5.0000 4.9995
7.7000 4.9988 4.9888 11.0000 5.0000 4.9995
7.8000 4.9989 4.9898 11.1000 5.0000 4.9996
7.9000 4.9990 4.9907 11.2000 5.0000 4.9996
8.0000 4.9991 4.9916 11.3000 5.0000 4.9996
8.1000 4.9992 4.9923 11.4000 5.0000 4.9997
8.2000 4.9993 4.9930 11.5000 5.0000 4.9997
8.3000 4.9994 4.9936 11.6000 5.0000 4.9997
8.4000 4.9994 4.9942 11.7000 5.0000 4.9998
8.5000 4.9995 4.9947 11.8000 5.0000 4.9998
8.6000 4.9995 4.9952 11.9000 5.0000 4.9998
8.7000 4.9996 4.9956 12.0000 5.0000 4.9998
8.8000 4.9996 4.9960 12.1000 5.0000 4.9998
8.9000 4.9997 4.9964 12.2000 5.0000 4.9999
9.0000 4.9997 4.9967 12.3000 5.0000 4.9999
9.1000 4.9997 4.9970 12.4000 5.0000 4.9999
9.2000 4.9998 4.9973 12.5000 5.0000 4.9999
9.3000 4.9998 4.9975 12.6000 5.0000 4.9999
9.4000 4.9998 4.9978 12.7000 5.0000 4.9999
12.8000 5.0000 4.9999
12.9000 5.0000 4.9999
13.0000 5.0000 4.9999
13.1000 5.0000 4.9999
13.2000 5.0000 4.9999
13.3000 5.0000 4.9999
13.4000 5.0000 5.0000
13.5000 5.0000 5.0000
13.6000 5.0000 5.0000
13.7000 5.0000 5.0000
13.8000 5.0000 5.0000
13.9000 5.0000 5.0000
14.0000 5.0000 5.0000
14.1000 5.0000 5.0000
14.2000 5.0000 5.0000
14.3000 5.0000 5.0000
14.4000 5.0000 5.0000
14.5000 5.0000 5.0000
14.6000 5.0000 5.0000
14.7000 5.0000 5.0000
14.8000 5.0000 5.0000
14.9000 5.0000 5.0000
15.0000 5.0000 5.0000
Graph:
MATLAB Code: twotankeuler848.m
clc
clear all
R1=1; % flow resistance of tank1 in ft/cfm%
R2=1; % flow resistance of tank2 in ft/cfm%
h(1)=1; % height of tank 1 in feet%
h2(1)=2; % height of tank 2 in feet%

q=5; % flow rate in 𝑓𝑡^3/min%

x=0.1; % increment for two tank non interacting%


t=0:0.1:15; % time in min%
fprintf('time h1 in ft h2 in ft\n') % printing results%
for i=1:150 % calculating loop%

q1=h(i)/R1; % flow rate of tank1 in 𝑓𝑡^3/min%

q2=h2(i)/R2; % flow rate of tank2 in 𝑓𝑡^3/min%


dh1=q-q1; % change in height of tank 1%
dh2=q1-q2; % change in height of tank 2%
h(i+1)=h(i)+(x*(5-q1)); % Euler equation%
h2(i+1)=h2(i)+(x*(q1-q2)); % Euler equation%
disp([t(i) h(i) h2(i)]) % display command%
end
plot(t,h,'k*') % plotting command%
hold on
plot(t,h2,'ko') % plotting command%
xlabel('time in sec') % for x axis%
ylabel('height of tank1 nd tank2 in feet') % for y axis%
title('graph between t v/s h and h2')
legend('h=height of tank1','h2=height of tank2')
Report:
Variation of height of liquid level in two tanks of a two tank non-interacting system with respect
to the time is calculated and plotted using Euler method in MATLAB. It was observed that as
time increases height of liquid level increases and attains steady state.
Problem No: Name: Jagadeesh Caszo.
Date: Roll No: 21021A0849.
TWO TANK NON- INTERACTING SYSTEM

Problem Statement:
Consider the following set of differential equations that describe two tank liquid level non-
interacting system.
𝑑ℎ1 ℎ1
= 𝑞 − 𝑞1 𝑤ℎ𝑒𝑟𝑒 𝑞1 =
𝑑𝑡 𝑅1
𝑑ℎ2 ℎ2
= 𝑞1 − 𝑞2 𝑤ℎ𝑒𝑟𝑒 𝑞2 =
𝑑𝑡 𝑅2
𝑓𝑡 3 𝑓𝑡
The Parameter values are q=5 𝑚𝑖𝑛 , 𝑅1 = 1 𝑐𝑓𝑚 , 𝑡 = 0 𝑡𝑜 15 𝑚𝑖𝑛. Increments is 0.1; h1=1 ft,
h2=2 ft.

Fig: two tank liquid level system


Output:
time h1 in ft h2 in ft time h1 in ft h2 in ft
0 1 2 3.1000 4.8474 4.3599
0.1000 1.4000 1.9000 3.2000 4.8627 4.4086
0.2000 1.7600 1.8500 3.3000 4.8764 4.4540
0.3000 2.0840 1.8410 3.4000 4.8887 4.4963
0.4000 2.3756 1.8653 3.5000 4.8999 4.5355
0.5000 2.6380 1.9163 3.6000 4.9099 4.5720
0.6000 2.8742 1.9885 3.7000 4.9189 4.6058
0.7000 3.0868 2.0771 3.8000 4.9270 4.6371
0.8000 3.2781 2.1780 3.9000 4.9343 4.6661
0.9000 3.4503 2.2881 4.0000 4.9409 4.6929
1.0000 3.6053 2.4043 4.1000 4.9468 4.7177
1.1000 3.7448 2.5244 4.2000 4.9521 4.7406
1.2000 3.8703 2.6464 4.3000 4.9569 4.7617
1.3000 3.9833 2.7688 4.4000 4.9612 4.7813
1.4000 4.0849 2.8903 4.5000 4.9651 4.7993
1.5000 4.1764 3.0097 4.6000 4.9686 4.8158
1.6000 4.2588 3.1264 4.7000 4.9717 4.8311
1.7000 4.3329 3.2396 4.8000 4.9745 4.8452
1.8000 4.3996 3.3490 4.9000 4.9771 4.8581
1.9000 4.4597 3.4540 5.0000 4.9794 4.8700
2.0000 4.5137 3.5546 5.1000 4.9814 4.8809
2.1000 4.5623 3.6505 5.2000 4.9833 4.8910
2.2000 4.6061 3.7417 5.3000 4.9850 4.9002
2.3000 4.6455 3.8281 5.4000 4.9865 4.9087
2.4000 4.6809 3.9099 5.5000 4.9878 4.9165
2.5000 4.7128 3.9870 5.6000 4.9890 4.9236
2.6000 4.7416 4.0596 5.7000 4.9901 4.9302
2.7000 4.7674 4.1278 5.8000 4.9911 4.9362
2.8000 4.7907 4.1917 5.9000 4.9920 4.9417
2.9000 4.8116 4.2516 6.0000 4.9928 4.9467
3.0000 4.8304 4.3076 6.1000 4.9935 4.9513
6.2000 4.9942 4.9555 9.5000 4.9998 4.9980
6.3000 4.9948 4.9594 9.6000 4.9998 4.9982
6.4000 4.9953 4.9629 9.7000 4.9999 4.9983
6.5000 4.9958 4.9662 9.8000 4.9999 4.9985
6.6000 4.9962 4.9691 9.9000 4.9999 4.9986
6.7000 4.9966 4.9718 10.0000 4.9999 4.9987
6.8000 4.9969 4.9743 10.1000 4.9999 4.9989
6.9000 4.9972 4.9766 10.2000 4.9999 4.9990
7.0000 4.9975 4.9786 10.3000 4.9999 4.9991
7.1000 4.9977 4.9805 10.4000 4.9999 4.9991
7.2000 4.9980 4.9822 10.5000 4.9999 4.9992
7.3000 4.9982 4.9838 10.6000 4.9999 4.9993
7.4000 4.9984 4.9852 10.7000 4.9999 4.9994
7.5000 4.9985 4.9866 10.8000 5.0000 4.9994
7.6000 4.9987 4.9878 10.9000 5.0000 4.9995
7.7000 4.9988 4.9888 11.0000 5.0000 4.9995
7.8000 4.9989 4.9898 11.1000 5.0000 4.9996
7.9000 4.9990 4.9907 11.2000 5.0000 4.9996
8.0000 4.9991 4.9916 11.3000 5.0000 4.9996
8.1000 4.9992 4.9923 11.4000 5.0000 4.9997
8.2000 4.9993 4.9930 11.5000 5.0000 4.9997
8.3000 4.9994 4.9936 11.6000 5.0000 4.9997
8.4000 4.9994 4.9942 11.7000 5.0000 4.9998
8.5000 4.9995 4.9947 11.8000 5.0000 4.9998
8.6000 4.9995 4.9952 11.9000 5.0000 4.9998
8.7000 4.9996 4.9956 12.0000 5.0000 4.9998
8.8000 4.9996 4.9960 12.1000 5.0000 4.9998
8.9000 4.9997 4.9964 12.2000 5.0000 4.9999
9.0000 4.9997 4.9967 12.3000 5.0000 4.9999
9.1000 4.9997 4.9970 12.4000 5.0000 4.9999
9.2000 4.9998 4.9973 12.5000 5.0000 4.9999
9.3000 4.9998 4.9975 12.6000 5.0000 4.9999
9.4000 4.9998 4.9978 12.7000 5.0000 4.9999
12.8000 5.0000 4.9999
12.9000 5.0000 4.9999
13.0000 5.0000 4.9999
13.1000 5.0000 4.9999
13.2000 5.0000 4.9999
13.3000 5.0000 4.9999
13.4000 5.0000 5.0000
13.5000 5.0000 5.0000
13.6000 5.0000 5.0000
13.7000 5.0000 5.0000
13.8000 5.0000 5.0000
13.9000 5.0000 5.0000
14.0000 5.0000 5.0000
14.1000 5.0000 5.0000
14.2000 5.0000 5.0000
14.3000 5.0000 5.0000
14.4000 5.0000 5.0000
14.5000 5.0000 5.0000
14.6000 5.0000 5.0000
14.7000 5.0000 5.0000
14.8000 5.0000 5.0000
14.9000 5.0000 5.0000
15.0000 5.0000 5.0000
Graph:
MATLAB Code: twotankrk848.m
clc
clear all
h=0.1; % increment for two tank non interacting%
t(1)=0; % time in min%
h1(1)=1; % height of tank 1 in feet%
h2(1)=2; % height of tank 2 in feet%
r1=1; % flow resistance of tank1 in ft/cfm%
r2=1; % flow resistance of tank2 in ft/cfm%

q=5; % flow rate in 𝑓𝑡^3/min%

fprintf('time h1 in ft h2 in ft\n') % printing results%


for i=1:150 % calculating loop%
t(i+1)=t(i)+h; % time in min%
dh=(q-(h1(i)/r1)); % change in height of tank 1%
k1=h*(q-h1(i)); % R-K parameter%
k2=h*(q-(h1(i)+(k1/2))); % R-K parameter%
k3=h*(q-(h1(i)+(k2/2))); % R-K parameter%
k4=h*(q-(h1(i)+k3)); % R-K parameter%
h1(i+1)=h1(i)+((1/6)*(k1+(2*k2)+(2*k3)+k4)); % R-K forth order equation%
dh2=(h1(i)/r1)-(h2(i)/r2); % change in height of tank 2%
p1=h*(h1(i)-h2(i)); % R-K parameter%
p2=h*((h1(i)+(k1/2))-((h2(i)+(k1/2)))); % R-K parameter%
p3=h*((h1(i)+(k2/2))-((h2(i)+(k2/2)))); % R-K parameter%
p4=h*((h1(i)+k3)-(h2(i)+k3)); % R-K parameter%
h2(i+1)=h2(i)+((1/6)*(p1+(2*p2)+(2*p3)+p4)); % R-K forth order equation%
disp([t(i+1) h1(i) h2(i)]) % display command%
end
plot(t,h1,'k*') %plot command%
hold on
plot(t,h2,'ko') %plot command%
xlabel('time in sec') % for x axis%
ylabel('height of tank1 and tank2 in feet') % for y axis%
title('graph between t v/s h&h2')
legend('h1=height of tank1','h2=height of tank2')
Report:
Variation of height of liquid level in two tanks of a two tank non-interacting system with respect
to the time is calculated and plotted using R-K 4th order method in MATLAB. It was observed
that as time increases height of liquid level increases and attains steady state.

You might also like