Sei sulla pagina 1di 8

NETAJI SUBHAS UNIVERSITY OF TECHNOLOGY

Industrial Electronics
(ICE Department)

Presentation on

Runge-Kutta Method

Submitted to: Submitted by:

Prof. Prerna Gaur Ankit Kumar


Nimish Kumar
Kartikey Kumar
Introduction

Introduction to Iterative methods: There are number of iterative methods typically


generate a sequence of estimates of the solution which is expected to converge to
the true solution. Runge-Kutta method is also one of the iterative methods which
are used to find the roots of given expression.
MATLAB Code
clc;
fileID = fopen('RKout.m','w');
h=0.1; a=0; b=3; % h is the step size, t=[a,b] t-range
t = a:h:b; % Computes t-array up to t=3
y = zeros(1,numel(t)); % Memory preallocation
y(1) = 5; % initial condition; in MATLAB indices start at 1
Fyt = @(t,y) 3.*exp(-t)-0.4*y; % change the function as you desire
% the function is the expression after (t,y)
% table title
fprintf((fileID),'%7s %7s %7s %7s %7s %7s %7s\n','i','t(i)','k1','k2','k3','k4','y(i)');
for ii=1:1:numel(t)
k1 = Fyt(t(ii),y(ii));
k2 = Fyt(t(ii)+0.5*h,y(ii)+0.5*h*k1);
k3 = Fyt((t(ii)+0.5*h),(y(ii)+0.5*h*k2));
k4 = Fyt((t(ii)+h),(y(ii)+h*k3));
y(ii+1) = y(ii) + (h/6)*(k1+2*k2+2*k3+k4); % main equation
% table data
fprintf(fileID,'%7d %7.2f %7.3f %7.3f',ii, t(ii), k1, k2);
fprintf(fileID,' %7.3f %7.3f %7.3f \n', k3, k4, y(ii));
end
y(numel(t))=[ ]; % erase the last computation of y(n+1)
% Solution PLOT:
plot(t,y,':*r')
title('RK-4--Numerical Solution---');
xlabel('t');
ylabel('y');
legend('numerical');
grid on
fclose(fileID);
Output
i t(i) k1 k2 k3 k4 y(i)
1 0.00 1.000 0.834 0.837 0.681 5.000
2 0.10 0.681 0.535 0.538 0.401 5.084
3 0.20 0.401 0.273 0.276 0.156 5.138
4 0.30 0.156 0.045 0.047 -0.057 5.165
5 0.40 -0.057 -0.154 -0.152 -0.242 5.170
6 0.50 -0.242 -0.326 -0.324 -0.402 5.155
7 0.60 -0.402 -0.475 -0.473 -0.540 5.122
8 0.70 -0.540 -0.602 -0.601 -0.658 5.075
9 0.80 -0.658 -0.711 -0.709 -0.758 5.015
10 0.90 -0.758 -0.802 -0.801 -0.842 4.944
11 1.00 -0.842 -0.879 -0.878 -0.912 4.864
12 1.10 -0.912 -0.942 -0.942 -0.969 4.776
13 1.20 -0.969 -0.994 -0.993 -1.015 4.682
14 1.30 -1.015 -1.035 -1.035 -1.052 4.583
15 1.40 -1.052 -1.067 -1.067 -1.080 4.479
16 1.50 -1.080 -1.091 -1.090 -1.100 4.372
17 1.60 -1.100 -1.107 -1.107 -1.113 4.263
18 1.70 -1.113 -1.118 -1.117 -1.121 4.153
19 1.80 -1.121 -1.122 -1.122 -1.123 4.041
20 1.90 -1.123 -1.122 -1.122 -1.121 3.929
21 2.00 -1.121 -1.118 -1.118 -1.115 3.817
22 2.10 -1.115 -1.110 -1.110 -1.105 3.705
23 2.20 -1.105 -1.099 -1.099 -1.093 3.594
24 2.30 -1.093 -1.086 -1.086 -1.078 3.484
25 2.40 -1.078 -1.070 -1.070 -1.061 3.375
26 2.50 -1.061 -1.052 -1.052 -1.042 3.268
27 2.60 -1.042 -1.032 -1.033 -1.022 3.163
28 2.70 -1.022 -1.012 -1.012 -1.001 3.060
29 2.80 -1.001 -0.990 -0.990 -0.979 2.959
30 2.90 -0.979 -0.967 -0.968 -0.956 2.860
31 3.00 -0.956 -0.944 -0.944 -0.932 2.763
THANK YOU

Potrebbero piacerti anche