differential equations without ode solvers

15 ビュー (過去 30 日間)
Taleb Bou Hamdan
Taleb Bou Hamdan 2019 年 2 月 25 日
コメント済み: Taleb Bou Hamdan 2019 年 2 月 27 日
hello, I am trying to simulate running two differential equaitons at the same time but there is an error that index exceeds array bounds:
The code am using is given in the following:
dt=0.5;
t=0:dt:10;
h1=zeros(size(t));
h1(1)=0;
h2=zeros(size(t));
h2(1)=0;
for i=1:21
if h1(i) < 1
h1= 0.5-0.065*sqrt(h1(i));
h2= 0.065*sqrt(h1(i)) - 0.1*sqrt(h2(i));
h1(i+1)= h1(i)+dt*h1;
h2(i+1)=h2(i)+dt*h2;
else h1(i)=1;
end

回答 (1 件)

Alex Mcaulley
Alex Mcaulley 2019 年 2 月 25 日
I think you are overwriting h1 and h2 variables in:
h1= 0.5-0.065*sqrt(h1(i));
h2= 0.065*sqrt(h1(i)) - 0.1*sqrt(h2(i));
After those lines h1 and h2 are scalars. Probably you need to put:
h1(i)= 0.5-0.065*sqrt(h1(i));
h2(i)= 0.065*sqrt(h1(i)) - 0.1*sqrt(h2(i));
  1 件のコメント
Taleb Bou Hamdan
Taleb Bou Hamdan 2019 年 2 月 27 日
Thank you. I have the names of the functions from h1 h2 to f1 and f2 and this solved the problem

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by