You are on page 1of 13

SEMM3023

Applied Numerical Methods


SECTION 31

Project Two
Submission date: 28/01/2023

Prepared by:

WALEED KHALED A19EM4039


MOAHMMED OMAR
AHMED ABDELHALIM A19EM4025
FARAG
Table of Contents
Problem Statement .................................................................................................. 2
Derivation of the governing equations .................................................................... 3
Theory and approach ............................................................................................... 4
Methodology............................................................................................................ 6
Source code ............................................................................................................. 8
Results………………………………………………………………………………………………………….………9
Discussion .............................................................................................................. 10
Conclusion .............................................................................................................. 11
References ............................................................................................................. 12

1
Problem Statement

A rocket has an initial mass of 1500 kg, in where 80% of this mass compromises of fuel. The
rocket burns fuel at a certain rate such that a constant thrust of 𝑇 = 36000 N is produced. Figure
1 demonstrates the forces acting on a rocket during take-off.

After takeoff, the mass of the rocket, 𝑚, reduces with time 𝑡 at a rate defined by equation (1):

𝑚=1500−40𝑡 (1)
At the same time, the rocket also experiences a drag for of:
𝑑𝑦
𝐹𝐷=0.02𝐺( )2 (2)
𝑑𝑡

𝑑𝑦
Where 𝐹𝐷 is the drag force experienced by the rocket, is the vertical velocity of the rocket
𝑑𝑡
and 𝐺 = 9.81 m/s2. Using Newton’s law, the equation of motion for the rocket can be expressed
as:
𝑑2𝑦
𝑚 = 𝑇 − 𝑚𝐺 − 𝐹𝐷 (3)
𝑑𝑡 2

2
Derivation of governing equations

General formula for the problem is given by:


𝑑2 𝑦
𝑚 = 𝑇 − 𝑚𝐺 − 𝐹𝐷
𝑑𝑡 2
𝑑2𝑦 𝑑𝑦
To drive the equation in terms of , 𝑎𝑛𝑑 𝑡:
𝑑𝑡 2 𝑑𝑡

𝑑2𝑦 𝑇−𝑚𝐺− 𝐹𝐷
=
𝑑𝑡 2 1500−40𝑡

Substituting the values for T, m Eq(1) and FD Eq(3) yields:


𝑑𝑦 2
𝑑2 𝑦 −0.1962 ( 𝑑𝑡 ) + 392.4𝑡 + 21285
=
𝑑𝑡 2 1500 − 40𝑡
At first, we assume:
𝑑𝑦
v=
𝑑𝑡
𝑑𝑣 𝑑2𝑦
therefore; =
𝑑𝑡 𝑑𝑡 2

𝑑𝑦 2
𝑑𝑣 −0.1962 ( 𝑑𝑡 ) + 392.4𝑡 + 21285
= … … 𝑒𝑞(4)
𝑑𝑡 1500 − 40𝑡

𝑑𝑦
= 𝑣 … … 𝑒𝑞(5)
𝑑𝑡

We obtain Eq(4) & Eq(5), which they are two first order ODE from the second order ODE
considered as the original equation, these two equations are required to solve the IVP problem.

3
Theory

To numerically solve for vertical displacement of the rocket, y there are multiple numerical
methods that qualify to approach the solution for the problem:
1- Euler’s Method
2- 4th Runge-Kutta Method
3- Adams Bashforth Method
4- Backward Difference Method
Commonly for this problem to numerically output the most accurate results while solving ODE
problems is by using 4th Runge-Kutta method which takes a weighted average of the slope at
more points than lower order RK methods, as it also more accurate than other methods since it
involves derivative calculations at multiple steps within the interval.
To implement this method, we are building a MATLAB code to calculate for the following steps
and solve the IVP problem.
The steps used to solve for vertical displacement of the rocket, y using 4th Runge-Kutta
method are as follows:
𝑑𝑦 𝑑2𝑦
i- Identifying the differential equations for , :
𝑑𝑡 𝑑𝑡 2

We can reduce the second order ODE to obtain Eq(4) by adding a new variable 𝑣 as following:
𝑑𝑦
𝑣= = 𝑓(𝑡, 𝑦, 𝑣 ) (1)
𝑑𝑡

𝑑𝑣 𝑑2𝑦
Since = , we can reduce the equation into a first order ODE and evaluate constants T,
𝑑𝑡 𝑑𝑡 2
g and m:
𝑑2𝑦 𝑑𝑣 −0.1962 𝑣 2 +392.4𝑡+21285
= = 𝑔(𝑡, 𝑦, 𝑣 ) = (2)
𝑑𝑡 2 𝑑𝑡 1500−40𝑡

ii- Defining initial values to solve for the IVP problem:

at t = 0 , y(0) = 0 , zero displacement at take-off.


at t=0 , v(0) = 0 , vertical velocity is zero at take-off.

4
iii- Applying 4th Runge-Kutta method (RK4):
The solution of the differential equations can be obtained by:

- yi+1 = yi + 1/6(k1+2k2+2k3+k4)h -------(3)


- vi+1 = vi + 1/6(j1+2j2+2j3+j4)h----------(4)
Coefficients can be obtained by iteration and adding up the values:

- k1= hf(𝑡0 , 𝑦0 , 𝑣0 )
- j1= hg(𝑡0 , 𝑦0 , 𝑣0 )
ℎ 𝑘1 𝑗
- k2= hf(𝑡0 + , 𝑦0 + , 𝑣0 + 1 )
2 2 2
ℎ 𝑘1 𝑗
- j2= hg(𝑡0 + , 𝑦0 + , 𝑣0 + 1 )
2 2 2
ℎ 𝑘2 𝑗
- k3= hf(𝑡0 + , 𝑦0 + , 𝑣0 + 2 )
2 2 2
ℎ 𝑘2 𝑗
- j3 = hg(𝑡0 + , 𝑦0 + , 𝑣0 + 2 )
2 2 2
ℎ 𝑘3
- k4 = ℎf(𝑡0 + , 𝑦0 + , 𝑣0 + 𝑗3 )
2 2
ℎ 𝑘3
- j4 = ℎg(𝑡0 + , 𝑦0 + , 𝑣0 + 𝑗3 )
2 2

5
Methodology

The algorithm that was used to write the code is as follows:


1- Define the initial conditions: t0, tf, y0 and v0.
2- Define the step size, h=1.
3- Define the time steps, 0 ≤ t ≤ 10.
4- Initialize empty arrays to store the values of y and z in order to use them to plot the
graph.
5- Implement 4th Order Runge-Kutta Method to solve the equations numerically by using
(for) loop function.
6- Inside the “for” loop function, define the two 1st order equations, k1, k2, k3, k4 and j1,
j2, j3, j4.
7- Plot the vertical displacement, y against Time, t. Write the title of the graph and label
both axes x and y.
8- Print the value of vertical displacement Y at t=10 (call y at i=11 since the “for” loop
function starts from i=2).

6
The flowchart that was used is as follows:

7
Source code
%project2

% Define initial conditions


t0 = 0;
tf = 10;
y0 = 0;
v0 = 0;
%define step size
h=1;
% Define time steps
t = t0:h:tf;

% Initialize y and v arrays


y = zeros(1,length(t));
v = zeros(1,length(t));
y(1) = y0;
v(1) = v0;

% Implement 4th Order Runge-Kutta Method to solve the eqautions numerically


for i = 2:length(t)
%define the two first order equations
dydt= @(t,y,v) v;
dvdt= @(t,y,v) (((-0.1962*(v^2))+392.4*t+21285)/(1500-40*t));
%define k1,k2,k3,k4 and j1,j2,j3,j4
k1 = dydt(t(i-1),y(i-1),v(i-1));
j1 = dvdt(t(i-1),y(i-1),v(i-1));
k2 = dydt(t(i-1)+h/2,y(i-1)+k1/2,v(i-1)+j1/2);
j2 = dvdt(t(i-1)+h/2,y(i-1)+k1/2,v(i-1)+j1/2);
k3 = dydt(t(i-1)+h/2,y(i-1)+k2/2,v(i-1)+j2/2);
j3 = dvdt(t(i-1)+h/2,y(i-1)+k2/2,v(i-1)+j2/2);
k4 = dydt(t(i-1)+h,y(i-1)+k3,v(i-1)+j3);
j4 = dvdt(t(i-1)+h,y(i-1)+k3,v(i-1)+j3);
y(i) = y(i-1) + (1/6)*(k1+2*k2+2*k3+k4)*h; %define the classical RK4 for y
v(i) = v(i-1) + (1/6)*(j1+2*j2+2*j3+j4)*h; %define the classical RK4 for v
t(i) = t(i-1) + h;
end

% Plot y against t
figure;
plot(t,y);
xlabel('Time (s)');
ylabel('Vertical Position (m)');
title('Vertical Displacement Vs Time');

%print the value of vertical displacement y at t=10 s


fprintf('the vertical displacement, y at t=10s is: %0.4f m \n\n',y(11)); %call y at
i=11 since the "for" loop function starts from i=2

8
Results

The final value for y at t=10 s is:

9
Discussion

The numerical approach and analytical method are both ways to solve initial value
problems (IVPs), but they differ in how they go about solving them. The numerical approach
involves using computational methods to approximate a solution to a problem, while the
analytical method involves using mathematical equations and theory to find an exact solution.
Although it may be very difficult or impossible to approach analytically that is when numerical
methods come in hand.
Since the numerical solution for a problem highly depends on how far a problem solution
can be approximated, as well as the numerical approach tendency to evaluate the solution of
problems within more steps to approximate the problem to its exact solution.
The method that was used to solve the problem given is 4th Runge-Kutta method. This
method is a numerical method used to solve ordinary differential equations. It is a type of
explicit Runge-Kutta method, which uses four estimates
The exact solution for vertical velocity of the rocket, y at t=10 is, y(10)exact = 800.2015 m.
On the other hand, by using 4th Runge-Kutta method the approximated solution for the problem
at t=10s was y(10)RK4 = 800.2017 m, which is relatively close to the analytical solution. To
calculate the percentage error %ε to relate both approaches:

Percentage error:
𝑦(10)𝑒𝑥𝑎𝑐𝑡− 𝑦(10)𝑅𝐾4
%ε = | | x100%
𝑦(10)𝑒𝑥𝑎𝑐𝑡

Therefore;
800.2015−800.2017
%ε = | | x100% = 0.000025%
800.2015

The percentage error is relatively infinitesimal. That tells us that the method used to solve
the problem numerically was pretty accurate since the numerical solution was almost same as the
analytical solution.

10
Conclusion

Finally, we can say that the 4th Runge-Kutta method (RK4) is the most suitable method
to solve second order differential equations with an initial value (IVP). Since it gave us a
solution that is so close to the exact solution with an error of 0.000025%, the percentage error for
the 4th Runge-Kutta solution is so small. However, it can also be lesser than that by optimizing
the method using adaptive step size h, in which the step size is small in points where the error is
big and larger step size exists in points where the error percentage is small. In other words, this
method is called 4th Adaptive Runge-Kutta method (ARK4), where the step size is adaptive to
obtain more accurate solution but in the cost of more computational resources. The step size is
based on the rate of changing for the solution whether it is slow or rapid.
Moreover, we can use higher order methods such as 5th Runge-Kutta (RK5) or 6th
Runge-Kutta (RK6). Where, RK5 uses five estimates of the solution to improve the accuracy of
the solution while RK6 uses six estimates of the solution for more accuracy improvement, but
they also require more computation. Therefore, 4th Runge-Kutta method seems to be the best
suitable method to solve initial value problems (IVP) in terms of computational efficiency and
accuracy.

11
References

1. Udwadia, F. E., & Farahani, A. (2008). Accelerated Runge-Kutta Methods. Discrete

Dynamics in Nature and Society, 2008, 1–38. https://doi.org/10.1155/2008/790619

2. Shampine, L., & Thompson, S. (2007). Initial value problems. Scholarpedia, 2(3), 2861.

https://doi.org/10.4249/scholarpedia.2861

3. Islam, Amirul. (2015). Accurate Solutions of Initial Value Problems for Ordinary

Differential Equations with the Fourth Order Runge Kutta Method.

10.5539/ijsp.v4n3p41.

12

You might also like