声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 2286|回复: 9

[求助]ODE4能否直接使用?

[复制链接]
发表于 2006-4-27 16:25 | 显示全部楼层 |阅读模式

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

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

x
在论坛上查到的帖子是讲的:现在在MATLAB Central站点,一些定时步长的函数可以直接利用。其中有ODE4 四阶龙格-库塔法。<BR>MATLAB Central站点是什么意思?我在HELP里也查不到ODE4函数<BR>急需求解定步长微分方程,有高手告诉我吗~~
回复
分享到:

使用道具 举报

发表于 2006-4-27 17:25 | 显示全部楼层
<P>ode4可以在sumulink 中可以直接使用。</P>
 楼主| 发表于 2006-4-27 17:47 | 显示全部楼层
simulink是电路相关的对吧?
发表于 2006-4-27 18:01 | 显示全部楼层
定步长的rk很好编程的,算法十分简洁,<BR>建议自己试试。
 楼主| 发表于 2006-4-27 18:05 | 显示全部楼层
rk是什么?汗……
发表于 2006-4-28 09:40 | 显示全部楼层

回复:(irewine)rk是什么?汗……

<DIV class=quote><B>以下是引用<I>irewine</I>在2006-4-27 18:05:08的发言:</B><BR>rk是什么?汗……</DIV>
<br>龙格-库塔法
发表于 2006-4-28 09:41 | 显示全部楼层

回复:(irewine)[求助]ODE4能否直接使用?

matlab中不自带这个函数<BR>matlab central是指<BR><a href="http://www.mathworks.com/matlabcentral/" target="_blank" >http://www.mathworks.com/matlabcentral/</A>
 楼主| 发表于 2006-4-28 10:22 | 显示全部楼层
感谢教授回答。<BR>ODE45无法实现定步长对吧?<BR>我现在毕业设计的一个关键步骤就是要龙格库塔法定步长解微分方程。有什么办法能在本机的matlab上使用ode4函数?
发表于 2006-4-30 18:57 | 显示全部楼层

回复:(irewine)感谢教授回答。ODE45无法实现定步长...

<DIV class=quote><B>以下是引用<I>irewine</I>在2006-4-28 10:22:03的发言:</B><br>感谢教授回答。<br>ODE45无法实现定步长对吧?<br>我现在毕业设计的一个关键步骤就是要龙格库塔法定步长解微分方程。有什么办法能在本机的matlab上使用ode4函数?</DIV><br>ode45可以实现等步长输出,但是计算的时候仍然是采用的是变步长<br><br><br>ode4.m<br><br>function [time, y_sol, y_drv] = ode4( dydt, time, y0, u, params )<br>% [time, y_sol, y_drv] = ode4( dydt, time, y0, u, params )<br>%<br>% Solve a system of nonhomogeneous ordinary differential equations using the <br>% 4th order Runge-Kutta method. <br>%<br>% Input Variable Description <br>% -------------- ----------- <br>% dydt : a function of the form y_dot = dydt(t,y,u,params)<br>% which provides the state derivative given <br>% the state, y, and the time, t <br>% time : a vector of points in time at which the solution <br>% is computed <br>% y0 : the initial value of the states <br>% params : vector of other parameters for dydt<br>% u : m-by-p matrix of forcing for the ode, where m<br>% m = number of inputs and n = length(time);<br>%<br>% Output Variable Description<br>% -------------- -----------<br>% time : is returned, un-changed<br>% y_sol : the solution to the differential equation at <br>% times given in the vector time.<br>%<br>% Henri Gavin, Civil and Environmental Engineering, Duke Univsersity, Jan. 2001<br>% WH Press, et al, Numerical Recipes in C, 1992, Section 16.1<br>points = length(time);<br>n = length(y0(:));<br>if nargin &lt; 5, params = 0; end<br>if nargin &lt; 4, u = zeros(1,points); end<br>y_sol = zeros(n,points); % memory allocation<br>y_drv = zeros(n,points); % memory allocation<br>y_sol(:,1) = y0(:); % the initial conditions<br>for p = 2:points<br>t = time(p); <br>dt = t - time(p-1); % the time step for this interval<br>dt2 = dt/2; % half of the time step<br>k1 = feval( dydt, t - dt, y0, u(:,p-1), params );<br>k2 = feval( dydt, t - dt2, y0 + k1*dt2, (u(:,p-1)+u(:,p))/2.0, params );<br>k3 = feval( dydt, t - dt2, y0 + k2*dt2, (u(:,p-1)+u(:,p))/2.0, params );<br>k4 = feval( dydt, t, y0 + k3*dt, u(:,p), params );<br>y0 = y0 + ( k1 + 2*(k2 + k3) + k4 )*dt/6; <br>y_sol(:,p) = y0(:);<br>y_drv(:,p-1) = k1(:);<br>end<br>
[此贴子已经被作者于2006-4-30 18:58:30编辑过]

发表于 2009-2-26 23:49 | 显示全部楼层
这个ode4能带参数不?
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

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

GMT+8, 2024-9-22 19:32 , Processed in 0.054284 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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