【源码】四阶龙格库塔法(Runge Kutta)求解常微分方程

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

MATLAB完整源代码:web

% It calculates ODE using Runge-Kutta 4th order method微信

% Author Ido Schwartzsvg

clc; % Clears the screenoop

clear all;3d

h=1.5; % step sizecode

x = 0:h:3; % Calculates upto y(3)xml

y = zeros(1,length(x));blog

y(1) = 5; % initial condition图片

F_xy = @(t,r) 3.exp(-t)-0.4r; % change the function as you desireget

for i=1:(length(x)-1) % calculation loop

k_1 = F_xy(x(i),y(i));

k_2 = F_xy(x(i)+0.5*h,y(i)+0.5*h*k_1);

k_3 = F_xy((x(i)+0.5*h),(y(i)+0.5*h*k_2));

k_4 = F_xy((x(i)+h),(y(i)+k_3*h));


y(i+1) = y(i) + (1/6)*(k_1+2*k_2+2*k_3+k_4)*h;  % main equation

end

关于PPT课件的下载地址:

Runge 4th Order Method.ppt

Runge_Kutta_4.m

http://page5.dfpan.com/fs/cl6c4j5292f19209160/

更多精彩文章请关注微信号:在这里插入图片描述