Error massage in Euler method

10 ビュー (過去 30 日間)
Barkin Senel
Barkin Senel 2019 年 10 月 21 日
回答済み: David Hill 2019 年 10 月 21 日
Hello,
I should write a code about euler method. I have generate the equation but the code show me a "Array indices must be positive integers or logical values Error in modes620_1 (line 6) u(0)=1;" error message. My code is
h=0.1;
c=30;
u=zeros(1:6);
v=zeros(1:6);
u(0)=1;
v(0)=-2;
for n=0:10;
u(n+1)=u(n)+h*v(n);
%v(n+1)=v(n)-((c*h)/3)*v(n)-16*u(n);
end
What should I do to correct this?
Thanks from now.

採用された回答

David Hill
David Hill 2019 年 10 月 21 日
Array indexes start at one not zero for MATLAB. You cannot index into an array at zero. Just start your array indexing at one instead.
u(1)=1;
v(1)=-2;

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by