写了一个m文件来解微​分方程,弄了两天了,​还是不行,求助。

内容如下:function dy = Function(t,x)
dy = zeros(2,1);
dy(1) = x(2);
dy(2) = sign(sin(t))+3*cos(t/2);
[t,x] = ode45(@Function,[0 10],[0 0]);
点击“Run”,提示如下:
而我按它的提示把t,x都输入0,又提示:
Attempted to access x(2); index out of bounds because numel(x)=1.
Error in Function (line 3)
dy(1) = x(2);
求助啊,因为这个忙了两天了,唉,无奈,新手,谢谢了先。

 采纳的回答

wopirig
wopirig 2022-11-18

0 个投票

[t,x] = ode45(@Function,[0 10],[0 0]);
这一句不是函数内容,上面的函数内容保存后,这一句是在命令行输入的。
如果点RUN,也应该找到其中的Run:type code to run,将type code to run换成[t,x] = ode45(@Function,[0 10],[0 0]);

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 MATLAB Report Generator 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!