声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 8998|回复: 40

[计算数学] 有没有ode45的matlab代码

[复制链接]
发表于 2007-10-14 13:55 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
rt
就是解一个微分方程,我不用现成的ode45
回复
分享到:

使用道具 举报

发表于 2007-10-14 14:05 | 显示全部楼层

回复 #1 sdlmx 的帖子

动手搜索一下,就会发现论坛里其实有很多你需要的东西。

function Y = ode4(odefun,tspan,y0,varargin)
%ODE4 Solve differential equations with a non-adaptive method of order 4.
% Y = ODE4(ODEFUN,TSPAN,Y0) with TSPAN = [T1, T2, T3, ... TN] integrates
% the system of differential equations y' = f(t,y) by stepping from T0 to
% T1 to TN. Function ODEFUN(T,Y) must return f(t,y) in a column vector.
% The vector Y0 is the initial conditions at T0. Each row in the solution
% array Y corresponds to a time specified in TSPAN.
%
% Y = ODE4(ODEFUN,TSPAN,Y0,P1,P2...) passes the additional parameters
% P1,P2... to the derivative function as ODEFUN(T,Y,P1,P2...).
%
% This is a non-adaptive solver. The step sequence is determined by TSPAN
% but the derivative function ODEFUN is evaluated multiple times per step.
% The solver implements the classical Runge-Kutta method of order 4.
%
% Example
% tspan = 0:0.1:20;
% y = ode4(@vdp1,tspan,[2 0]);
% plot(tspan,y(:,1));
% solves the system y' = vdp1(t,y) with a constant step size of 0.1,
% and plots the first component of the solution.
%
if ~isnumeric(tspan)
error('TSPAN should be a vector of integration steps.');
end
if ~isnumeric(y0)
error('Y0 should be a vector of initial conditions.');
end
h = diff(tspan);
if any(sign(h(1))*h <= 0)
error('Entries of TSPAN are not in order.')
end
try
f0 = feval(odefun,tspan(1),y0,varargin{:});
catch
msg = ['Unable to evaluate the ODEFUN at t0,y0. ',lasterr];
error(msg);
end
y0 = y0(:); % Make a column vector.
if ~isequal(size(y0),size(f0))
error('Inconsistent sizes of Y0 and f(t0,y0).');
end
neq = length(y0);
N = length(tspan);
Y = zeros(neq,N);
F = zeros(neq,4);
Y(:,1) = y0;
for i = 2:N
ti = tspan(i-1);
hi = h(i-1);
yi = Y(:,i-1);
F(:,1) = feval(odefun,ti,yi,varargin{:});
F(:,2) = feval(odefun,ti+0.5*hi,yi+0.5*hi*F(:,1),varargin{:});
F(:,3) = feval(odefun,ti+0.5*hi,yi+0.5*hi*F(:,2),varargin{:});
F(:,4) = feval(odefun,tspan(i),yi+hi*F(:,3),varargin{:});
Y(:,i) = yi + (hi/6)*(F(:,1) + 2*F(:,2) + 2*F(:,3) + F(:,4));
end
Y = Y.';

评分

1

查看全部评分

发表于 2007-10-14 15:03 | 显示全部楼层
问个外行的问题:oed4和ode45什么区别呀?我觉得现成的ode45用着就很方便呀,楼主为啥不要呢?
发表于 2007-10-14 15:16 | 显示全部楼层
这个应该是设计精度等问题吧,像ode45和ode15的差别
发表于 2007-10-14 15:50 | 显示全部楼层

回复 #3 花如月 的帖子

ode4是定步长的,ode45是自适应变步长的
发表于 2007-10-14 15:57 | 显示全部楼层

回复 #5 zhlong 的帖子

你那里有没有有关ode45编程原理的基础内容,就是他是如何解微分方程的?我是说原理,用的那个方法,如何迭代?
发表于 2007-10-14 16:05 | 显示全部楼层

回复 #6 咕噜噜 的帖子

薛定宇、陈阳泉 著 《高等应用数学问题的MATLAB求解》一书p212页有介绍。
发表于 2007-10-14 16:17 | 显示全部楼层
1.png
在实际问题往往希望在一些情况下(如解变化很快时)采用较小的步长,而在另一些情况下(如解的变化很缓慢时)采用较大的步长,这样做既可以保证较高的精度,又可以保证较高的运行速度。在此算法中定义一个误差向量 2.png ,可以由它的大小来变换计算长度,所以这种能自动变换步长的方法又称为自适应变步长方法
发表于 2007-10-14 16:21 | 显示全部楼层
电子版有没有,发来一份
phoenycs@126.com
发表于 2007-10-14 16:30 | 显示全部楼层

回复 #9 咕噜噜 的帖子

这一章的PPT关于这个的只有这一页,已发到你邮箱。
发表于 2007-10-14 19:41 | 显示全部楼层

回复 #6 咕噜噜 的帖子

你说的这些在很多书上都有,例如陈予恕《非线性振动》,胡海岩《应用非线性动力学》上面都有讲述,然后一些数值分析书中都有相应的介绍的!
发表于 2007-10-14 20:07 | 显示全部楼层
直接在matlab中输入:
edit ode45
发表于 2007-10-14 22:23 | 显示全部楼层
发表于 2007-10-15 10:21 | 显示全部楼层

回复 #11 octopussheng 的帖子

oct骗人,找了陈予恕的书没找到,胡海岩的书中倒是提到了3-4阶Runge-Kutaa方法,可无水说ode45是6阶的,:@L :@L 4阶的Runge-Kutaa我也可以找到啦,告诉我6阶的
发表于 2007-10-15 12:27 | 显示全部楼层

回复 #14 咕噜噜 的帖子

那本英文书你找到没有?
上面有说明哈
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-5-13 10:12 , Processed in 0.062325 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表