gpt4 book ai didi

matlab - 我如何强制 ode45 在 T 轴上采取精确的 0.01 步长?

转载 作者:太空宇宙 更新时间:2023-11-03 19:37:23 32 4
gpt4 key购买 nike

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

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

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);

最佳答案

基于 the documentation在求解方程时,您似乎无法控制 ode45 内部采取的步长,但您可以控制生成输出的时间点.您可以按照注释掉的行中的指示执行此操作:

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

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

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.

因此,即使您在输出中指定您想要在特定时间点的解决方案,求解器仍在内部采取一些适应性步骤您指定的时间点之间,接近到那些固定时间点的值。

关于matlab - 我如何强制 ode45 在 T 轴上采取精确的 0.01 步长?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2549238/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com