如何强制ode45在T轴上采取恰好0.01的步长? [英] How do I force ode45 to take steps of exactly 0.01 on the T axis?

查看:284
本文介绍了如何强制ode45在T轴上采取恰好0.01的步长?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Matlab求解微分方程.我想强制ode45采取恒定的步长,因此在求解方程式时它总是在T轴上增加0.01.我该怎么做?

I'm using Matlab to solve a differential equation. I want to force ode45 to take constant steps, so it always increments 0.01 on the T axis while solving the equation. How do I do this?

ode45始终采取优化的随机步骤,而且我似乎无法弄清楚如何使之采取0.01的较小的一致步骤.这是代码:

ode45 is consistently taking optimized, random steps, and I can't seem to work out how to make it take consistent, small steps of 0.01. Here is the code:

options= odeset('Reltol',0.001,'Stats','on');

%figure(1);
%clf;
init=[xo yo zo]';
tspan=[to tf];
%tspan = t0:0.01:tf;

[T,Y]=ode45(name,tspan,init,options);

推荐答案

基于文档,看来您无法控制ode45在求解方程式时内部执行的步长,但可以控制输出的时间点生成.您可以按照注释行中的指示进行操作:

Based on the documentation it doesn't appear that you can control the size of the steps taken internally by ode45 when solving the equation, but you can control the time points at which the output is generated. You can do this as indicated in your commented-out line:

tspan = to:0.01:tf;  % Obtain solution at specific times
[T, Y] = ode45(name, tspan, init, options);

关于使用固定步长时解决方案的准确性,请参考以上链接的摘录:

With respect to the accuracy of solutions when fixed step sizes are used, refer to this excerpt from the above link:

如果tspan具有两个以上的元素[t0,t1,t2,...,tf],则求解器将返回在给定点处求值的解.但是,求解器不能精确地步进到tspan中指定的每个点.取而代之的是,求解器使用其自己的内部步骤来计算解决方案,然后在tspan中的请求点上评估解决方案.在指定点产生的解的准确性与在每个内部步骤计算出的解的准确性相同.

If tspan has more than two elements [t0,t1,t2,...,tf], then the solver returns the solution evaluated at the given points. However, the solver does not step precisely to each point specified in tspan. Instead, the solver uses its own internal steps to compute the solution, then evaluates the solution at the requested points in tspan. The solutions produced at the specified points are of the same order of accuracy as the solutions computed at each internal step.

指定几个中间点对计算效率几乎没有影响,但是对于大型系统,它会影响内存管理.

Specifying several intermediate points has little effect on the efficiency of computation, but for large systems it can affect memory management.

因此,即使您指定要在输出中的特定时间点进行求解,求解器仍会在内部在您指示的时间点之间 采取许多自适应步骤,从而逐渐接近到固定时间点的值.

So, even when you specify that you want the solution at specific time points in the output, the solvers are still internally taking a number of adaptive steps between the time points that you indicate, coming close to the values at those fixed time points.

这篇关于如何强制ode45在T轴上采取恰好0.01的步长?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆