Professional Documents
Culture Documents
POWER ELECTRONICS
Report on
NUMERICAL SOLUTION OF FIRST ORDER DIFFERENTIAL
EQUATION USING RUNGE KUTTA METHOD
Submitted by,
Runge-Kutta methods are designed to solve first-order differential equations. They can be
used on a single first-order ODE or on a coupled system of first-order ODEs. If a higher-order
ODE can be expressed as a coupled system of first-order ODEs, Runge-Kutta methods can be
used to solve it. To understand how Runge-Kutta methods work, consider a simple first-order
differential equation.
= f(x,y)
Page 1 of 10
To solve for the dependent variable y, can be integrated in a step-wise manner. The derivative is
replaced by its delta-form and the x term is moved to the right-hand side.
y = yn+1 - yn = x f(x,y)
Starting at an independent variable location xn where the value of yn is known, the value
of the dependent variable at the next location, yn+1, is equal to its value at the current location, yn,
added to the independent variable step size, x, times the right-hand side function. There is one
question left to be resolved, where should we evaluate the right-hand side function? With the
Euler method, as shown above, the function is evaluated at the current location, xn.
There are numerous Runge-Kutta schemes of various orders of accuracy. The most
commonly used scheme and the one we will implement is the fourth-order Runge-Kutta
algorithm. As the name implies, it is fourth order accurate in x.The algorithm consists of five
steps, four successive approximations of and a fifth step that computes yn+1 based on a linear
combination of the successive approximations.
Page 2 of 10
OBJECTIVE:
Our objective is to solve the first order differential equation numerically without the
calculation of partial derivatives (ie analytical method) using Runge-Kutta algorithm. Consider
the single variable problem x' = f (t, x) with initial condition x(0) = x0. Suppose that xn is the
value of the variable at time tn.
The Runge-Kutta formula takes xn and tn and calculates an approximation for xn+1 at a
brief time later, tn+h. It uses a weighted average of approximated values of f (t, x) at several
times within the interval (tn, tn+h).
For real-life problems first and second order methods are not applicable, because within
reasonable computational time we cannot achieve the numerical solution with some prescribed
and required (by the application) accuracy.
Our aim is to construct higher order accurate methods most numerical solutions to
differential equations is to attain the desired accuracy with the fewest computations, which, for
any given method means running it with the smallest step size that satisfies the accuracy
conditions.
The formula is given by
To run the simulation, we simply start with x0 and find x1 using the formula above. Then
we plug in x1 to find x2 and so on. The Runge-Kutta algorithm is known to be very accurate and
well-behaved for a wide range of problems.
The Runge-Kutta algorithm can be easily extended to a set of first order differential
equations. You wind up with essentially the same formulas shown above, but all the variables
(except for time) are vectors.
Page 3 of 10
Sources of error, convergence, and stability
It is important to keep in mind that there are three possible sources of error in numerical
calculations, such as solutions to ordinary differential equations. The one we have discussed the
most is truncation error, the error associated with the number of terms in a series, e.g. Taylor
series.
Other sources of error are round-off errors, which will always be present even if our
method is exact, and original data errors, associated with not knowing the initial conditions or
boundary conditions exactly. Errors at each step propagate through the solution, so the global
error is generally about an order larger than the local error.
A method is convergent if the approximate solution tends toward the true solution as step
size tends to zero. All of the widely used methods for solving ordinary differential equations (in
particular the ones we have discussed) are convergent. Stability refers to the growth of errors as
the solution proceeds. A stable method is one in which the global error does not grow in an
unbounded manner. For many ODE's, the step size required to obtain an accurate solution is
much smaller than the step size required for stability. As a result, stability is often not a major
concern. When a solution is unstable, it is usually obvious. A smaller step size will generally
rectify the problem, although there are cases that are unconditionally unstable for some methods.
Changing methods is the best approach in such cases.
Page 4 of 10
FLOW CHART
Start
Get values of
Initial time t0, Initial output y0, Step size h, Final time
t
Initialize tn = t0 ; yn=y0
If
tn<= tf
No
Yes
Stop
Page 5 of 10
Example:
RL Circuit:
SW
R
I
Vs
DC
L
Circuit Parameters:
Vs 20V ;
R=2Ω ;
L=4mΗ
Differential Equation:
di
Vs =iR+L
dt
di V R
= s- i
dt L L
di 20 2
= - i
dt 0.04 0.04
Solution for the above equation using analytical method:
-2 t
20 0.04
i= (1-e )
2
Page 6 of 10
MATLAB CODE:
clc
clear
% Initial output Values
Y = [0 5 20];
% Step Size
h = [0.005];
h0 = h;
% Value of t at which solution needs to be found
tf = 0.5;
% Initial time
t = [0];
t0 = t;
for i = 1:length(y) % for different initial output values
n = tf / h;
c = zeros (1,n+1);
d = zeros (1,n+1);
c (1) = t;
d (1) = y (i);
for xx = 1 : n
% Iteration process for different initial output values
%Runge kutta Fourth order method
k1 = h * diffeqn2 (t,y(i));
k2 =h * diffeqn2 (t+h/2,y(i)+k1/2);
Page 7 of 10
k3 = h * diffeqn2(t+h/2,y(i)+k2/2);
k4 = h * diffeqn2(t+h,y(i)+k3);
y(i) = y(i) + 1/6 * (k1+2*k2+2*k3+k4);
t = t + h;
fprintf ( ' End of Iteration %d using %d intial output value : tn+1= %f,
yn+1 = %f \n ', xx, i, t, y(i));
fprintf('%f %f \n', t, y(i));
c(xx+1) = t;
d(xx+1) = y(i);
end
plot(c,d);
hold on
t=t0;
h=h0;
end
y
% Function call
function [y1]=diffeqn2(t,y)
y1= ((20/.04) - ((2/0.04)*y));
end
Page 8 of 10
Output Waveform for different initial output assumptions:
15
Current (A)
10
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7
Time((S)
The below table shows that results from both analytical and numerical methods using RK
method and error corresponds to them.
.
Numerical Analytical
Time(s) Error(A-N)
method(N) method(A)
0.005 2.211914 2.211992169 0.0000781690
0.010 3.934572 3.934693403 0.0001214030
0.015 5.276192 5.276334473 0.0001424730
0.020 6.321058 6.321205588 0.0001475880
0.025 7.134808 7.134952031 0.0001440310
0.05 9.179068 9.179150014 0.0000820140
0.075 9.764787 9.764822541 0.0000355410
0.1 9.932607 9.93262053 0.0000135300
0.125 9.980691 9.980695459 0.0000044590
0.150 9.994467 9.994469156 0.0000021560
0.175 9.998415 9.998415387 0.0000003870
0.4 10.000000 9.999999979 -0.0000000210
0.5 10.000000 10 0.0000000000
Page 9 of 10
INFERENCES:
The step size and initial value of the variable were found to be the most influential
parameters for the performance of the Runge-Kutta method. It was found that with different
initial values, the function y=f(t) varies accordingly, if the function is of linear nature. Whereas
for functions which reaches a steady state the initial value does not have any influence on the
steady state value.
The step size was found to be a parameter which varies with different types of problems.
In electrical problems relating to transients it was found that the time constant of the circuit can
be used to determine the function accurately. For the function to be predicted accurately during
the transient period and steady state period, the step size must have a minimum value of 5% of
the time constant in the circuit whose differential equation needs to be solved. Whereas in order
to predict only the steady state value the step size must have a minimum value of 250% of the
time constant.
REFERENCES
1. P. Kandasamy, K. Thilagavathy and K. Gunavathy, ‘Numerical Methods’, S.Chand Co.
Ltd., New Delhi, 2003.
3. www.nptel.ac.in
4. www.mathworks.in
Page 10 of 10