Numerical Solution of Second Order Ordinary Differential Equation Using Fourth Order Runge-Kutta Method
Numerical Solution of Second Order Ordinary Differential Equation Using Fourth Order Runge-Kutta Method
net/publication/380721364
CITATIONS READS
0 539
1 author:
SEE PROFILE
All content following this page was uploaded by Muhammad Abdullah Zafar Ghauri on 20 May 2024.
Abstract— This document focuses on optimal solution of a simple 2 nd order Ordinary Differential Equation
using 4th Order Runge-Kutta Method. Runge Kutta method is an effective numerical technique to solve ODEs
with high accuracy factor. An advanced version of Euler Method and Taylor Method, the method is
commonly used in predicting mathematical models and approaching for obtaining appropriate solutions. The
document primarily focuses on MATLAB approach to solve the 2 nd order ODE with aforementioned
technique.
Keywords— Ordinary Differential Equation, Euler Method, Taylor Method, Runge-Kutta Method,
Optimization
INTRODUCTION
In numerical analysis, the Runge–Kutta methods are a family of implicit and explicit iterative methods, which
include the Euler method, used in temporal discretization for the approximate solutions of simultaneous
nonlinear equations. These methods were developed around 1900 by the German mathematicians Carl Runge
and Wilhelm Kutta. Runge–Kutta method is an effective and widely used method for solving the initial-value
problems of differential equations. Runge–Kutta method can be used to construct high order accurate numerical
method by functions' self without needing the high order derivatives of functions.
MATLAB is a very powerful software package that has many built-in tools for solving problems and for
graphical illustrations. The name MATLAB stands for MATrix LABoratory. The heart of MATLAB is the
MATLAB language, a matrix-based language allowing the most natural expression of computational
mathematics. The package MATLAB provides an environment in which we can learn to programme and
explore the structure of the numerical methods.
Figure 2 General Interface of MATLAB R2024a
INTRODUCTION TO METHOD
The Runge-Kutta 2nd order method is a numerical technique used to solve an ordinary differential equation of
the form:
The 2nd Order Runge Kutta method is restricted to solving the general ODEs of the following form mentioned
above. can be solved by using the Runge-Kutta 2nd order method. In other sections, we discuss how the Euler
and Runge-Kutta methods are used to solve higher-order ordinary or coupled (simultaneous) ordinary
differential equations.
Here it stands for y being an unknown function (scalar or vector) defined for some time interval t and of y itself
meant for approximation at which y changes slowly, which is function of t and y itself. At some initial time to,
the corresponding y value is yo. The function f and the initial conditions to, yo are usually provided.
Referring to some step value, h which is greater in value than 0, it may be well defined as
Here yn+1 is the RK 4 approximation of y(tn+1) and the next value yn+1 is determined usually from the present
value yn plus the weighted average of four different incremenets, where each increment is the product of the size
of the interval, h, and some estimated slope specified by some function f for the right-hand side of the
differential equation.
• k1 is the slope at the beginning of the interval, using y (Euler’s Method)
• k2 is the slope at the midpoint of the interval, using y and k 1
• k3 is again the slope of the midpoint, but by y and k 2
• k4 is the slope at the end of the interval, defined by y and k 3
In averaging the four slopes, greater weight is given to the slopes at the midpoint. If the function f is
independent of y, so that the differential equation is equivalent to a simple integral, then RK4 is Simpson's rule.
PROBLEM STATEMENT
MATLAB CODE
• First Approach:
% Final temperature
theta_final = theta(end);
• Second Approach:
% Define the function representing the rate of change of temperature
function dthetadt = f(t, theta)
% Assuming constant surrounding temperature (T_surrounding)
T_surrounding = 20; % Adjust this value as needed (in degrees Celsius)
dthetadt = -5.33e-6 * (-3.69e-6*theta^4 + 2.33e-5*theta^3 + 1.35e-
3*theta^2 + 0.0542*theta + 5.888)*(33+theta);
end
% Set up parameters
t0 = 0; % Initial time
tfinal = 86400; % Final time (86400 seconds)
% Choose a smaller step size for better accuracy (adjust as needed)
h = tfinal/200; % Example: Divide total time into 200 steps
% Initial condition
theta0 = 27; % Initial temperature (27 degrees Celsius)
% Solve using Runge-Kutta method
theta = theta0;
t = linspace(t0, tfinal, (tfinal-t0)/h + 1);
for i = 1:length(t)-1
% Kutta coefficients
k1 = (h)*f(t(i), theta);
k2 = (h)*f(t(i) + 1/2, theta + 1/2*k1);
k3 = (h)*f(t(i) + 1/2, theta + 1/2*k2);
k4 = (h)*f(t(i) + 1, theta + 1*k3);
% Update solution
theta = theta + (1/6)*(k1 + 2*k2 + 2*k3 + k4);
end
% Final temperature
theta_final = theta(end);
% Display the final temperature
fprintf('The temperature of the steel shaft after 86400 seconds is %.2f
degrees Celsius.\n', theta_final);
% Optional: Plot the temperature change over time
plot(t, theta)
xlabel('Time (seconds)')
ylabel('Temperature (degrees Celsius)')
title('Temperature of Steel Shaft over Time')
OBTAINED RESULTS
CONCLUSIONS
In conclusion, it may be asserted that Runge Kutta methods play a significant role in numerical modelling with
significantly swift convergence rates and relatively greater accuracy factor. MATLAB plays a significant role in
engineering roles in appropriate modelling for different scenarios.
REFERENCES
[1] Kutta, Wilhelm (1901), "Beitrag zur näherungsweisen Integration totaler Differentialgleichungen", Zeitschrift für Mathematik und
Physik, 46: 435–453.
[2] Attaway, Stormy. Matlab: A Practical Introduction to Programming and Problem Solving. Canada : Elsevier, Inc., 2009
[3] Gilat, Amos. MATLAB An Introduction with Applications. Columbia, Ohio : John Wiley & Sons, Inc., 2011.
[4] Press et al. 2007, p. 908; Süli & Mayers 2003, p. 328
[5] Atkinson (1989, p. 423), Hairer, Nørsett & Wanner (1993, p. 134), Kaw & Kalu (2008, §8.4) and Stoer & Bulirsch (2002, p. 476)
leave out the factor h in the definition of the stages. Ascher & Petzold (1998, p. 81), Butcher (2008, p. 93) and Iserles (1996, p. 38)
use the y values as stages.
[6] Süli & Mayers 2003, p. 328
[7] A. K. Kaw, “Runge-Kutta 4th order method,” in Numerical Methods with Applications, 2010.