KEMBAR78
Rimon Numerical 10 | PDF | Differential Equations | Ordinary Differential Equation
0% found this document useful (0 votes)
30 views4 pages

Rimon Numerical 10

The document outlines an experiment focused on solving first-order ordinary differential equations (ODEs) using various numerical methods, including Euler’s Method, Heun’s Method, Modified Euler’s Method, and Runge-Kutta 4th Order Method. It discusses the implementation of these methods, their accuracy, and the comparison of their results against the exact solution. The conclusion highlights that while Euler’s method is the simplest, the Runge-Kutta 4th Order Method offers the best accuracy and stability for solving ODEs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views4 pages

Rimon Numerical 10

The document outlines an experiment focused on solving first-order ordinary differential equations (ODEs) using various numerical methods, including Euler’s Method, Heun’s Method, Modified Euler’s Method, and Runge-Kutta 4th Order Method. It discusses the implementation of these methods, their accuracy, and the comparison of their results against the exact solution. The conclusion highlights that while Euler’s method is the simplest, the Runge-Kutta 4th Order Method offers the best accuracy and stability for solving ODEs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Exp No: 10

Exp name: Solving ordinary differential equation using various numerical methods (Euler’s
Method, Heun’s Method, Modified Euler’s/Runge Kutta 2nd Order Method, Runge Kutta 4th Order
Method.

Objectives:

1. To understand and implement numerical methods for solving first-order ordinary


differential equations (ODEs).
2. To compare the accuracy and behavior of the following numerical methods.
3. To analyze the approximation of the solution over a given interval and compare it with
the exact (analytical) solution if available.

Theory:
An Ordinary Differential Equation (ODE) is an equation involving a function and its derivatives.
Many physical systems—such as motion, electrical circuits, population models, and fluid
dynamics—can be modeled using ODEs. Often, it is difficult or impossible to obtain exact
analytical solutions for such equations. In such cases, numerical methods provide an approximate
solution by computing the value of the function at discrete points.
Ordinary Differential Equations (ODEs) represent relationships between functions of a single
independent variable and their derivatives. When finding analytical solutions to these equations
proves challenging or unattainable, numerical methods serve as valuable tools to estimate solutions
effectively. These methods enable researchers and engineers to tackle complex problems across
various fields, where precise analytical solutions may not exist.
We solve the differential equation,
𝑑𝑦
= 𝑓(𝑥, 𝑦) = 4𝑒 0.8𝑥 − 0.5𝑦
𝑑𝑥

Euler’s Method
Euler's method is a straightforward first-order numerical technique used for solving ordinary
differential equations (ODEs).
𝑠𝑡𝑒𝑝 𝑠𝑖𝑧𝑒, ℎ = 𝑥1 − 𝑥0

𝑦𝑘+1 = 𝑦𝑘 + ℎ𝑓(𝑥𝑘 , 𝑦𝑘 )
Heun’s Method
Heun's method enhances Euler's method by employing a predictor-corrector approach. Initially, a
prediction is generated using Euler's method, followed by a second prediction, or corrector step,
that averages the slopes at both the start and end of the interval.

𝑦𝑘+1 = 𝑦𝑘 + [𝑓(𝑥𝑘 , 𝑦𝑘 ) + 𝑓(𝑥𝑘+1 , 𝑦𝑘+1 )]
2

Modified Euler’s/Runge Kutta 2nd Order Method


The Modified Euler’s method, also known as the Runge-Kutta 2nd Order method, involves a
similar predictor-corrector approach but gives more emphasis to the evaluation of the function at
the mid-point of the interval.

𝑓1 = 𝑓(𝑥𝑘 , 𝑦𝑘 )

ℎ ℎ
𝑓2 = 𝑓 (𝑥𝑘 + , 𝑦𝑘 + 𝑓1 )
2 2
𝑦𝑘+1 = 𝑦𝑘 + ℎ𝑓2

Runge Kutta 4th Order Method


The Runge-Kutta 4th Order method is one of the most accurate and widely used methods for
solving ODEs. It computes four intermediate values 𝑓1 , 𝑓2 , 𝑓3 , 𝑓4 to estimate the slope and then
averages them to get the next value of y.

𝑓1 = 𝑓(𝑥𝑘 , 𝑦𝑘 )

ℎ ℎ
𝑓2 = 𝑓 (𝑥𝑘 + , 𝑦𝑘 + 𝑓1 )
2 2
ℎ ℎ
𝑓3 = 𝑓 (𝑥𝑘 + , 𝑦𝑘 + 𝑓2 )
2 2
𝑓4 = 𝑓(𝑥𝑘 + ℎ, 𝑦𝑘 + ℎ𝑓3 )


𝑦𝑘+1 = 𝑦𝑘 + [𝑓1 + 2𝑓2 + 2𝑓3 + 𝑓4 ]
6
MATLAB Code & Output:
clc
clear all
close all
f = @(x,y)(4*exp(0.8*x)-0.5*y);

x0 = 0; y0 = 1; h = 0.5;
xn=5;
x = x0:h:xn;
n = length(x);

y_euler = zeros(1, n);


y_heun = zeros(1, n);
y_mod_euler = zeros(1, n);
y_rk4 = zeros(1, n);

y_euler(1) = y0;
y_heun(1) = y0;
y_mod_euler(1) = y0;
y_rk4(1) = y0;

for i = 1:n-1

y_euler(i+1) = y_euler(i) + h * f(x(i), y_euler(i));

y_pred = y_heun(i) + h * f(x(i), y_heun(i));


y_heun(i+1) = y_heun(i) + (h/2)*(f(x(i), y_heun(i)) + f(x(i+1), y_pred));

k1 = h * f(x(i), y_mod_euler(i));
k2 = h * f(x(i) + h/2, y_mod_euler(i) + k1/2);
y_mod_euler(i+1) = y_mod_euler(i) + k2;

k1 = h * f(x(i), y_rk4(i));
k2 = h * f(x(i) + h/2, y_rk4(i) + k1/2);
k3 = h * f(x(i) + h/2, y_rk4(i) + k2/2);
k4 = h * f(x(i) + h, y_rk4(i) + k3);
y_rk4(i+1) = y_rk4(i) + (1/6)*(k1 + 2*k2 + 2*k3 + k4);
end

hold on ;
plot(x, y_euler, '-o', 'DisplayName', 'Euler');

plot(x, y_heun, '-s', 'DisplayName', 'Heun');

plot(x, y_mod_euler, '-^', 'DisplayName', 'Modified Euler (RK2)');

plot(x, y_rk4, '-x', 'DisplayName', 'RK4');


xlabel('x'); ylabel('y');
title('Comparison of Numerical Methods for dy/dx = x + y');
legend show;
grid on;

Output:

Fig. 10.1 Output of the given Methods

Discussion & Conclusion:

In this experiment, we solved a first-order ODE using four numerical methods: Euler’s Method,
Heun’s Method, Modified Euler’s Method (RK2), and Runge-Kutta 4th Order Method (RK4).
Among them, Euler’s method is the simplest but least accurate due to its large error accumulation.
Heun’s and Modified Euler’s methods improve accuracy by averaging or evaluating slopes at
intermediate points. RK4 provides the best accuracy with four slope evaluations per step, making
it highly reliable for precise applications.
As observed, smaller step sizes improve accuracy for all methods, but RK4 achieves high precision
even with moderately large steps. Overall, RK4 is the most efficient method for solving ODEs
when both accuracy and stability are important.

You might also like