5th Order Runge Kutta

54 views (last 30 days)
Chris Potts
Chris Potts on 30 Jan 2018
Answered: Suganya V.P on 24 Feb 2023
Hey,
I've been looking at Runge Kutta methods and was wondering how we would write a 5th order runge kutta method. I've stumbled upon lot of work online about how to write to the 4th order but not the 5th?
I've been looking at the code below...
% It calculates ODE using Runge-Kutta 4th order method
% Author Ido Schwartz
% Originally available form: http://www.mathworks.com/matlabcentral/fileexchange/29851-runge-kutta-4th-order-ode/content/Runge_Kutta_4.m
% Edited by Amin A. Mohammed, for 2 ODEs(April 2016)
clc; % Clears the screen
clear all;
h=0.1; % step size
x = 0:h:1; % Calculates upto y(1)
y = zeros(1,length(x));
z = zeros(1,length(x));
y(1) = 3; % initial condition
z(1) = 1; % initial condition
% F_xy = @(t,r) 3.*exp(-t)-0.4*r; % change the function as you desire
F_xyz = @(x,y,z) z; % change the function as you desire
G_xyz = @(x,y,z) 6*y-z;
for i=1:(length(x)-1) % calculation loop
k_1 = F_xyz(x(i),y(i),z(i));
L_1 = G_xyz(x(i),y(i),z(i));
k_2 = F_xyz(x(i)+0.5*h,y(i)+0.5*h*k_1,z(i)+0.5*h*L_1);
L_2 = G_xyz(x(i)+0.5*h,y(i)+0.5*h*k_1,z(i)+0.5*h*L_1);
k_3 = F_xyz((x(i)+0.5*h),(y(i)+0.5*h*k_2),(z(i)+0.5*h*L_2));
L_3 = G_xyz((x(i)+0.5*h),(y(i)+0.5*h*k_2),(z(i)+0.5*h*L_2));
k_4 = F_xyz((x(i)+h),(y(i)+k_3*h),(z(i)+L_3*h)); % Corrected
L_4 = G_xyz((x(i)+h),(y(i)+k_3*h),(z(i)+L_3*h));
%k_5
%L_5
y(i+1) = y(i) + (1/6)*(k_1+2*k_2+2*k_3+k_4)*h; % main equation
z(i+1) = z(i) + (1/6)*(L_1+2*L_2+2*L_3+L_4)*h; % main equation
end
Anyone have any ideas in what the 5th order equations should be and how to implement it to this code?
Many Thanks Chris
  3 Comments
Chris Potts
Chris Potts on 5 Feb 2018
Edited: Chris Potts on 5 Feb 2018
just follow this method, it's not too difficult
krishna kadiyam
krishna kadiyam on 5 Feb 2018
thank u man!!!

Sign in to comment.

Accepted Answer

James Tursa
James Tursa on 30 Jan 2018
E.g., 5th Order Runge-Kutta-Fehlberg coefficients can be found here:

More Answers (1)

Suganya V.P
Suganya V.P on 24 Feb 2023

ATLAB AnswersToggle Sub Navigation 5th Order Runge Kutta 134 views (last 30 days) Show older comments Chris Potts Chris Potts on 30 Jan 2018 ⋮ Commented: krishna kadiyam on 5 Feb 2018 Accepted Answer: James Tursa Hey, I've been looking at Runge Kutta methods and was wondering how we would write a 5th order runge kutta method. I've stumbled upon lot of work online about how to write to the 4th order but not the 5th? I've been looking at the code below... % It calculates ODE using Runge-Kutta 4th order method % Author Ido Schwartz % Originally available form: http://www.mathworks.com/matlabcentral/fileexchange/29851-runge-kutta-4th-order-ode/content/Runge_Kutta_4.m % Edited by Amin A. Mohammed, for 2 ODEs(April 2016) clc; % Clears the screen clear all; h=0.1; % step size x = 0:h:1; % Calculates upto y(1) y = zeros(1,length(x)); z = zeros(1,length(x)); y(1) = 3; % initial condition z(1) = 1; % initial condition % F_xy = @(t,r) 3.*exp(-t)-0.4*r; % change the function as you desire F_xyz = @(x,y,z) z; % change the function as you desire G_xyz = @(x,y,z) 6*y-z; for i=1:(length(x)-1) % calculation loop k_1 = F_xyz(x(i),y(i),z(i)); L_1 = G_xyz(x(i),y(i),z(i)); k_2 = F_xyz(x(i)+0.5*h,y(i)+0.5*h*k_1,z(i)+0.5*h*L_1); L_2 = G_xyz(x(i)+0.5*h,y(i)+0.5*h*k_1,z(i)+0.5*h*L_1); k_3 = F_xyz((x(i)+0.5*h),(y(i)+0.5*h*k_2),(z(i)+0.5*h*L_2)); L_3 = G_xyz((x(i)+0.5*h),(y(i)+0.5*h*k_2),(z(i)+0.5*h*L_2)); k_4 = F_xyz((x(i)+h),(y(i)+k_3*h),(z(i)+L_3*h)); % Corrected L_4 = G_xyz((x(i)+h),(y(i)+k_3*h),(z(i)+L_3*h)); %k_5 %L_5 y(i+1) = y(i) + (1/6)*(k_1+2*k_2+2*k_3+k_4)*h; % main equation z(i+1) = z(i) + (1/6)*(L_1+2*L_2+2*L_3+L_4)*h; % main equation end

Categories

Find more on Numerical Integration and Differential Equations in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!