Silly question but how can I plot a simple ODE like the following?
My ODE is:
dy/dt=1-(t/n)-y
where n is an array
n=[1 2 3 5 Inf]

 採用された回答

darova
darova 2020 年 5 月 3 日
編集済み: darova 2020 年 5 月 3 日

0 投票

Use for loop to solve equation 5 times for each n
n = [1 2 3 5 inf];
f = @(t,y,n) 1-t/n+y;
for i = 1:length(n)
[t,y] = ode45(f,[0 5],ic,[],n(i));
line(t,y)
end

6 件のコメント

Ameer Hamza
Ameer Hamza 2020 年 5 月 3 日
編集済み: Ameer Hamza 2020 年 5 月 3 日
This syntax of ode45 is obsolete and no longer documented. Using new documented syntax will avoid any confusion for the readers
n = [1 2 3 5 inf];
f = @(t,y,n) 1-t/n-y;
ic = 1;
for i = 1:length(n)
[t,y] = ode45(@(t,y) f(t,y,n(i)), [0 5], ic);
line(t,y)
end
Even for the obsolete syntax, the correct line is
[t,y] = ode45(f,[0 5], ic, [], n(i));
darova
darova 2020 年 5 月 3 日
Don't know what you are talking about
Ameer Hamza
Ameer Hamza 2020 年 5 月 3 日
Sorry!! I pasted the wrong code.
Carlos Ojeda
Carlos Ojeda 2020 年 5 月 3 日
Is there a way to make each line a different color?
darova
darova 2020 年 5 月 3 日
Of course
line(t,y,'color',rand(1,3))
Carlos Ojeda
Carlos Ojeda 2020 年 5 月 3 日
Thank you, kindly, sir!

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

その他の回答 (0 件)

カテゴリ

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by