Professional Documents
Culture Documents
DEGAPUDI
PRABHADITYA
Date : 09/05/2021 Registration Number: 18BCM0078
AIM:
To develop a MATLAB code to solve the given ordinary differential equation (ODE) using
Runge-Kutta (R-K) 4th order method and compare it with Euler, Modified Euler methods and
analytical solution represents the results using the graph.
The velocity of a falling parachutist is given by the following equation:
dv cv
=g−
dt m
where, v is velocity (m/s), t is time (s), g is the acceleration due to gravity (9.81 m/s2), c is the
drag coefficient (kg/s), and m is mass (kg). Take c = 12.5 kg/s and m = 68 kg.
Initial Condition: At t = 0 s; v = 0 m/s. ie., v(0) = 0.
v(t) =
gm
(1− exp− (c/ m)t )
c
Plot graph v vs. t for all the above 2 methods with varying the step size h=2, h=4, h=6, h= 8,
h=10. Time starts from 0 s to 60 s.
Required formula:
h
y =y+ ( f (t , y ) + f (t , y + hf (t , y ) ) → Modified Euler's Method
i+1 i i i i+1 i i i
2
THEORY:
Euler’s Method :
Euler method (also called forward Euler method) is a first-order numerical procedure
for solving ordinary differential equations (ODEs) with a given initial value. The Euler
method is a first-order method, which means that the local error (error per step) is
proportional to the square of the step size, and the global error (error at a given time) is
proportional to the step size. Consider the problem of calculating the shape of an unknown
curve which starts at a given point and satisfies a given differential equation. Here, a
differential equation can be thought of as a formula by which the slope of the tangent line to
the curve can be computed at any point on the curve, once the position of that point has been
calculated. The idea is that while the curve is initially unknown, its starting point, which we
denote by A0. Then, from the differential equation, the slope to the curve at A0 can be
computed, and so, the tangent line. Take a small step along that tangent line up to a point A1.
Along this small step, the slope does not change too much, so A1 will be close to the curve. If
we pretend that A1 is still on the curve, the same reasoning as for the point A0 above can be
used. After several steps, a polygonal curve A0 , A1 , A2 , A3 … is computed. In general, this
curve does not diverge too far from the original unknown curve, and the error between the
two curves can be made small if the step size is small enough and the interval of computation
is finite.
Formula :
The Euler forward scheme may be very easy to implement but it can't give accurate
solutions. A very small step size is required for any meaningful result. In this scheme,
since, the starting point of each sub-interval is used to find the slope of the solution
curve, the solution would be correct only if the function is linear. So an improvement over
this is to take the arithmetic average of the slopes at xi and xi+1(that is, at the end points of
each sub-interval). The scheme so obtained is called modified Euler's method. It works first
by approximating a value to yi+1 and then improving it by making use of average slope.
Formula:
ℎ
𝑦𝑖+1 = 𝑦𝑖 + (𝑓(𝑡𝑖, 𝑦𝑖) + 𝑓(𝑡𝑖+1, 𝑦𝑖 + ℎ𝑓(𝑡𝑖, 𝑦𝑖) )
2
Runge – Kutta 4th Order Method :
Formula :
1
𝑦𝑖+1 = 𝑦𝑖 + [𝑘1 + 2𝑘2 + 2𝑘3 + 𝑘4] × ℎ
6
𝑘1 = 𝑓(𝑥𝑖, 𝑦𝑖)
1 1
𝑘2 = 𝑓(𝑥𝑖 + ℎ, 𝑦𝑖 + 𝑘1ℎ)
2 2
1 1
𝑘3 = 𝑓 (𝑥𝑖 + ℎ, 𝑦𝑖 + 𝑘2ℎ)
2 2
𝑘4 = 𝑓(𝑥𝑖 + ℎ, 𝑦𝑖 + 𝑘3ℎ)
RESULTS AND DISCUSSIONS:
MATLAB Code :
clear all
clc
f=@(x,y) 10- ((12.5*y)/68);
x0=input('Enter the initial value of x: ');
y0=input('Enter the initial value of y: ');
xn=input('Enter the final value of x: ');
h=input('Enter the step value: ');
y1(1)=y0;
y2(1)=y0;
y3(1)=y0;
y4(1)=y0;
ti(1)=x0;
for i=1:100
ti(i+1)=ti(i)+h;
k_1 = f(ti(i),y3(i));
k_2 = f(ti(i)+0.5*h,y3(i)+0.5*h*k_1);
k_3 = f((ti(i)+0.5*h),(y3(i)+0.5*h*k_2));
k_4 = f((ti(i)+h),(y3(i)+k_3*h));
y1(i+1)= y1(i)+ (f(ti(i),y1(i))*h);
y2(i+1)=
y2(i)+(h/2)*(f(ti(i),y2(i))+f(ti(i),y2(i)+h*f(ti(i),y2(i)
)));
y3(i+1)= y3(i) + (1/6)*(k_1+2*k_2+2*k_3+k_4)*h;
y4(i+1)=((10*68)/(12.5))*(1-exp(-(12.5/68)*ti(i+1)));
if ti(i)>=xn
n=i;
break;
end
end
fprintf('\n Iteration time(s) velocity(m/s)
');
for i=1:n
fprintf('\n %d %4.3f %4.3f
',i,ti(i),y1(i));
fprintf('\n %d %4.3f %4.3f
',i,ti(i),y2(i));
fprintf('\n %d %4.3f %4.3f
',i,ti(i),y3(i));
fprintf('\n %d %4.3f %4.3f
',i,ti(i),y4(i));
end
fprintf('\n');
plot(ti,y1);
hold on;
plot(ti,y2);
hold on;
plot(ti,y3);
hold on;
plot(ti,y4);
xlabel('Time');
ylabel('Velocity');
title('Velocity of a parachutist');
legend('Euler Method','Modified Euler Method','RK 4th
Order Method','Analytical Method');
Output :
1. For Step-Size h = 2 :
2. For Step-Size h = 4 :
3. For Step-Size h = 6 :