解决方案结构 sol=ode45 与 [t,y]=ode45 相比具有不同的时间步数

问题描述

作为 Matlab 的初学者,我正在使用包含要求解的 ode 方程的 test.m 探索 ode45 函数

在编辑器中,我通过 2 个选项调用函数。在一种情况下,我定义了 选项 1

t=[0 50];
y0=[0 2];
[t,y]=ode45(@(t,y)test(t,y),t,y0);

在选项 2 中我要求一个结构输出

t=[0 50];
y0=[0 2];
sol=ode45(@(t,y0);

然而,与选项 1 相比,结构选项 2 的结果时间步长更少,因此我的图“更粗糙”。

我找不到增加步骤数的方法来优化选项 2 的解决方案......有什么想法吗?

解决方法

deval 函数与 sol 和您选择的时间点一起使用。例如,

tSpan = 0:0.01:50;
y = deval(sol,tSpan);
plot(tSpan,y)

参见文档中的 Evaluate and Extend Solution Structure