写了一个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에 대해 자세히 알아보기

태그

질문:

2022년 11월 18일

답변:

2022년 11월 18일

Community Treasure Hunt

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

Start Hunting!