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

krishna kadiyam
krishna kadiyam 2018년 2월 5일
bro..have u gotten the solution? if u have gotten pls share with me also
Chris Potts
Chris Potts 2018년 2월 5일
편집: Chris Potts 2018년 2월 5일
just follow this method, it's not too difficult
krishna kadiyam
krishna kadiyam 2018년 2월 5일
thank u man!!!

댓글을 달려면 로그인하십시오.

 채택된 답변

James Tursa
James Tursa 2018년 1월 30일

0 개 추천

E.g., 5th Order Runge-Kutta-Fehlberg coefficients can be found here:

추가 답변 (1개)

Suganya V.P
Suganya V.P 2023년 2월 24일

0 개 추천

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

카테고리

도움말 센터File Exchange에서 Environment and Settings에 대해 자세히 알아보기

질문:

2018년 1월 30일

답변:

2023년 2월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by