24小时热门版块排行榜    

查看: 1925  |  回复: 3
【奖励】 本帖被评价1次,作者xiegangmai增加金币 0.6

[资源] 【资源】Runge-Kutta解ODE的一些程序及应用(from MathWorks) 已有2人参与

从MathWorks上找了些Runge-Kutta算法及应用的源码,转到这里,希望对要解常微分方程(组)的虫友有借鉴。

1、Runge Kutta 4th order ode(用四阶RK法解ODE)

https://www.mathworks.com/matlabcentral/fileexchange/29851-runge-kutta-4th-order-ode

by Judah S
29 Dec 2010
Code covered by the BSD License
CODE:
%It calculates ODE using Runge-Kutta 4th order method
%Author Ido Schwartz

clc; %Clears the screen
clear all;

h=1.5; %step size
x = 0:h:3; % Calculates upto y(3)
y = zeros(1,length(x));
y(1) = 5;
F_xy = @(t,r) 3.*exp(-t)-0.4*r; %change the function as you desire

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

2.  sixth order Runge-Kutta ODE(It calculates 6th order RK ODE using Fehlberg formulation)

https://www.mathworks.com/matlabcentral/fileexchange/29931-6th-order-runge-kutta-ode

by Judah S
06 Jan 2011
Code covered by the BSD License
CODE:
clc
clf
clear all

% % Author
%  Judah S
% Sixth Order RK-Fehlberg Equation
% Function y' + 2xy = 0; initial condition y(0)=1; where 0 <= x <= 10
% You can easily change the function and rest condition according to your
% requirment.
   fcnstr='-2*x*y' ;
   f=inline(fcnstr) ;

   x0=0 ;
   y0=1 ;

% xf, x location at where you wish to see the solution to the ODE

   xf=10 ;

% n, number of steps to take

   n=5 ;

format long g
h=(xf-x0)/n ;
xa(1)=x0 ;
ya(1)=y0 ;

for i=1:n
    % Adding Step Size
  xa(i+1)=xa(i)+h ;

% Calculating k1, k2, k3, k4, K5 and K6
  k1 = f(xa(i),ya(i)) ;
  k2 = f(xa(i)+(1/4)*h,ya(i)+(1/4)*k1*h) ;
  k3 = f(xa(i)+(3/8)*h,ya(i)+(3/32)*h*(k1+3*k2)) ;
  k4 = f(xa(i)+(12/13)*h,ya(i)+(12/2197)*h*(161*k1-600*k2+608*k3)) ;
  k5 = f(xa(i)+h,ya(i)+(1/4104)*h*(8341*k1-32832*k2+29440*k3-845*k4)) ;
  k6 = f(xa(i)+(0.5)*h,ya(i)+h*(-(8/27)*k1+2*k2-(3544/2565)*k3+(1859/4104)*k4-(11/40)*k5)) ;
% Using 6th Order Runge-Kutta formula
  ya(i+1)=ya(i)+1/5*((16/27)*k1+(6656/2565)*k3+(28561/11286)*k4-(9/10)*k5+(2/11)*k6)*h ;

  end


disp(sprintf('\n\n********************************Results**********************************'))

% The following finds what is called the 'Exact' solution
xspan = [x0 xf];
[x,y]=ode45(f,xspan,y0);
[yfi dummy]=size(y);
yf=y(yfi);

% Plotting the Exact and Approximate solution of the ODE.
hold on
xlabel('x');ylabel('y');
title('Exact and Approximate Solution of the ODE by the 4th Order Runge-Kutta Method');
plot(x,y,'--','LineWidth',2,'Color',[0 0 1]);            
plot(xa,ya,'-','LineWidth',2,'Color',[0 1 0]);
legend('Exact','Approximation');


disp(sprintf('\n   Approximate = %g',ya(n+1)))
disp(sprintf('   Exact       = %g',yf))
disp(sprintf('\n   True Error = Exact - Approximate'))
disp(sprintf('              = %g - %g',yf,ya(n+1)))
disp(sprintf('              = %g',yf-ya(n+1)))
disp(sprintf('\n   Absolute Relative True Error Percentage'))
disp(sprintf('              = | ( Exact - Approximate ) / Exact | * 100'))
disp(sprintf('              = | %g / %g | * 100',yf-ya(n+1),yf))
disp(sprintf('              = %g',abs( (yf-ya(n+1))/yf )*100))

3. RKN1210 - A 12th/10th order Runge-Kutta-Nystrom integrator(Integrator for second-order ODE's with very stringent error tolerances)

https://www.mathworks.com/matlabcentral/fileexchange/25291-rkn1210-a-12th10th-order-runge-kutta-nystrom-integrator

by Rody Oldenhuis
11 Sep 2009 (Updated 28 Oct 2010)
Code covered by the BSD License
源码及示例见上面链接。

4. Accurate Fast Marching(Multistencils second order Fast Marching 2D and 3D including rk4 shortest path and skeletonize)

https://www.mathworks.com/matlabcentral/fileexchange/24531-accurate-fast-marching

by Dirk-Jan Kroon
23 Jun 2009 (Updated 21 Dec 2010)
Code covered by the BSD License
源码比较多,感兴趣就请从上面的链接下吧。

5. double pendulum(the function is GUI that simulate double pendulum,the function is GUI that simulate double pendulum by using 4th-order Runge-Kutta algorithm for the differential equations)

https://www.mathworks.com/matlabcentral/fileexchange/28490-double-pendulum

by Moshe Lindner
16 Aug 2010
Code covered by the BSD License
源码见以上连接。

6. Weighted Kinematic Control of PPRR Manipulator(PPRR机械手运动控制)

https://www.mathworks.com/matlabcentral/fileexchange/23910-weighted-kinematic-control-of-pprr-manipulator

by Hrishi Shah
26 Apr 2009 (Updated 16 Feb 2010)
Code covered by the BSD License
源码见以上链接。

7. Program to Solve initial value problems by various methods(求解初值问题)

https://www.mathworks.com/matlabcentral/fileexchange/24614-program-to-solve-initial-value-problems-by-various-methods

by Daniel Klawitter
01 Jul 2009 (Updated 01 Jul 2009)
Code covered by the BSD License
很实用的初值问题求解代码,下载见以上链接。

8. Mackey-Glass time series generator(generates a Mackey-Glass time series using the 4-th order Runge-Kutta method)

https://www.mathworks.com/matlabcentral/fileexchange/24390-mackey-glass-time-series-generator

by Marco Cococcioni
09 Jun 2009
Code covered by the BSD License

9. CHAO-AND-HEART-DATABASE(Each volume is composed of figures of simulations with matlab R2007a, with runge kutta 4,with comments.)

https://www.mathworks.com/matlabcentral/fileexchange/24272-chao-and-heart-database

by Dit Papa Lamine ndao
27 May 2009
Code covered by the BSD License

10. Cardiac Chao with modele pacemaker VI1(The model is electrical stimulated with current Io=constant or Io=Asinwt.The model is integrated with runge kutta and R2007a.)

https://www.mathworks.com/matlabcentral/fileexchange/21531-cardiac-chao-with-modele-pacemaker-vi1

by Dit Papa Lamine ndao
24 Sep 2008 (Updated 24 Sep 2008)
No BSD License

11. Runge Kutta Ballistic Propagation(一个弹道的计算程序)

https://www.mathworks.com/matlabcentral/fileexchange/16626-runge-kutta-ballistic-propagation

by Luke
27 Sep 2007 (Updated 28 Sep 2007)
No SD License

12. M-File Comput N°1 Of Model Pacemaker VI1 Of All The Cardiac Cells With R2007a(computing with runge kutta 4 model pacemaker VI1 for all the cardiac cells)

https://www.mathworks.com/matlabcentral/fileexchange/16039-m-file-comput-n%C2%B01-of-model-pacemaker-vi1-of-all-the-cardiac-cells-with-r2007a

by Dit Papa Lamine NDao
21 Aug 2007 (Updated 22 Aug 2007)
No BSD License

13. Designing Algorith and Programation Of Cardiac Software Guide with Mat Lab(algorith and programation of a guide computing the symbolic model pacemake)

https://www.mathworks.com/matlabcentral/fileexchange/15840-designing-algorith-and-programation-of-cardiac-software-guide-with-mat-lab

by Dit Papa Lamine NDao
06 Aug 2007 (Updated 06 Aug 2007)
No BSD License

14. M-File Application OF Model Pcemaker VI1 of Cardiac Cells With Runge Kutta 4

https://www.mathworks.com/matlabcentral/fileexchange/15795-m-file-application-of-model-pcemaker-vi1-of-cardiac-cells-with-runge-kutta-4

by Dit Papa Lamine NDao
02 Aug 2007 (Updated 02 Aug 2007)
No BSD License

15. ROCK4(explicit solver for stiff equations)

https://www.mathworks.com/matlabcentral/fileexchange/12129-rock4

by Gerd Steinebach
01 Sep 2006 (Updated 01 Sep 2006)
No BSD License

16. Symplectic Integrators(Symplectic integrators for separable and nonseparable Hamiltonians)

https://www.mathworks.com/matlabcentral/fileexchange/7686-symplectic-integrators

by Francisco Beron-Vera
18 May 2005 (Updated 21 Jul 2006)
Code covered by the BSD License

17. TriStream(Compute streamlines on triangular mesh)

https://www.mathworks.com/matlabcentral/fileexchange/11278-tristream

by Matthew Wolinsky
02 Jun 2006 (Updated 06 Jun 2006)
No BSD License

18. equationGUI(A simple GUI for ODE (van der pol-prey predator - logistic model) and PDE (vibrating string))

https://www.mathworks.com/matlabcentral/fileexchange/10784-equationgui

by giancarlo zaccone
18 Apr 2006 (Updated 20 Apr 2006)
Code covered by the BSD License

19. fieldlines3D(fieldlines3D(X,Y,Z,U,V,W,x0,y0,z0) plots a field line with the initial point P(x0,y0,z0).The matrices X,Y,Z,U,V,and W must all be the same size and contain corresponding position and field components.The function employs the 4th order Runge-Kutta method for solving numerically differential equation y'=f(x,y).)

https://www.mathworks.com/matlabcentral/fileexchange/7768-fieldlines3d

by Avni Pllana
02 Jun 2005 (Updated 06 Jun 2005)
Code covered by the BSD License

20. fieldlines(Plots a field line with the initial point P(x0,y0) for a 2D-field.)

https://www.mathworks.com/matlabcentral/fileexchange/5710-fieldlines

by Avni Pllana
14 Aug 2004 (Updated 18 Aug 2004)
Code covered by the BSD License

21. Dynamics of Some Classical System Models(Animated response of some classical systems)

https://www.mathworks.com/matlabcentral/fileexchange/6558-dynamics-of-some-classical-system-models

by Howard Wilson
15 Dec 2004 (Updated 20 Dec 2004)
No BSD License

22. rkn86(Solves numerically a system of ODEs of the form d^2 y/ dx^2=f(x,y).)

https://www.mathworks.com/matlabcentral/fileexchange/3153-rkn86

by Charalampos Tsitouras
17 Mar 2003 (Updated 20 Feb 2004)
No BSD License

23. ode87 Integrator(integrates ode system with high accuracy)

https://www.mathworks.com/matlabcentral/fileexchange/3616-ode87-integrator

by Vasiliy Govorukhin
18 Jun 2003 (Updated 19 Jun 2003)
Code covered by the BSD License

24. ode86(integrates a system of ordinary differential equations at stringent tolerances)

https://www.mathworks.com/matlabcentral/fileexchange/2911-ode86

by Charalampos Tsitouras
06 Jan 2003 (Updated 07 Jan 2003)
No BSD License
回复此楼

» 收录本帖的淘帖专辑推荐

数值计算/matlab(学习集) 计算数学与经济统计 matlab software

» 猜你喜欢

» 本主题相关价值贴推荐,对您同样有帮助:

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

493971521

银虫 (小有名气)


2楼2011-01-10 13:37:33
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
简单回复
blue.wh3楼
2011-01-10 14:13   回复  
2014-05-04 15:06   回复  
三星好评  顶
相关版块跳转 我要订阅楼主 xiegangmai 的主题更新
☆ 无星级 ★ 一星级 ★★★ 三星级 ★★★★★ 五星级
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 售SCI一区T0P文章,我:8.O.55.1.O54,科目全,可伽急 +3 u1xkze8ybe 2026-07-30 7/350 2026-07-31 12:10 by syhhffkrym
[论文投稿] 售SCI一区T0P文章,我:8.O.55.1.O.5.4,科目全,可+急 +3 u1xkze8ybe 2026-07-30 3/150 2026-07-31 12:08 by syhhffkrym
[硕博家园] 售SCI一区T0P文章,我:8.O.55.1.O.5.4,科目全,可+急 +3 u1xkze8ybe 2026-07-30 6/300 2026-07-31 12:05 by syhhffkrym
[教师之家] 基础研究怎么拉横向,学校到款任务越来越多,难以完成 拉横向,都有哪些途径啊 +6 锦衣卫寒战 2026-07-28 6/300 2026-07-31 11:27 by syl200707
[高分子] HXDI做水性聚氨酯乳液,是不是特别容易出渣 15+3 yuyusuv 2026-07-29 3/150 2026-07-31 09:21 by huizingga
[基金申请] 小木虫看见有人已经知道结果了 +15 1234567wang 2026-07-25 19/950 2026-07-31 08:30 by ZJTJZ
[基金申请] 2026年国自然面上资助率 +8 布布和一二 2026-07-30 8/400 2026-07-31 01:51 by alongwaytogo
[基金申请] 系统今天又提示维护了,估计离放榜不远了 +11 winnerche 2026-07-29 15/750 2026-07-30 23:08 by jnhyjjm
[基金申请] 微信指数没变化,科研之友没阅读 +14 wangze12014 2026-07-28 17/850 2026-07-30 20:10 by kissu88
[考博] 申请2027年材料/化学类博士 10+3 考研老狗? 2026-07-25 5/250 2026-07-30 19:33 by 白色木鱼
[基金申请] 你们的时间戳变了吗 +3 archvillain 2026-07-30 4/200 2026-07-30 18:53 by levinzhwen
[基金申请] 今年的WR进展到哪一步了? +5 wsgjhwz 2026-07-25 9/450 2026-07-30 12:59 by 可淡不可忘
[有机交流] 产物和副产物价值比较 30+4 小汤02 2026-07-27 5/250 2026-07-30 12:44 by czyzsu
[基金申请] 时间戳他又来了 +14 晓晓爱翠翠 2026-07-26 17/850 2026-07-29 16:30 by 呵呵二哥
[有机交流] 这个自发加氧反应的机理是什么? 50+4 YUAN2273 2026-07-25 7/350 2026-07-29 12:27 by xiaobenpu
[基金申请] 没消息就是被刷了呗 +13 lambert2014 2026-07-24 14/700 2026-07-29 10:38 by msh145800
[基金申请] 这种情况还有戏吗 +5 drbart 2026-07-27 11/550 2026-07-29 05:50 by drbart
[基金申请] 同事接到电话了,我却没有 +4 1234567wang 2026-07-27 4/200 2026-07-28 10:11 by GOODLUCKER
[基金申请] 准备明年的基金了 +5 Tide man 2026-07-27 5/250 2026-07-28 09:25 by newfuzzy1
[分析] 水蒸气蒸馏法乳化现象 +3 月光娇娇 2026-07-26 3/150 2026-07-26 23:25 by caiyun
信息提示
请填处理意见