写了一个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);
求助啊,因为这个忙了两天了,唉,无奈,新手,谢谢了先。

 Réponse acceptée

wopirig
wopirig le 18 Nov 2022

0 votes

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

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB Report Generator dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!