How to plot 2 differential equations

42 ビュー (過去 30 日間)
Az Zahra Hazimah
Az Zahra Hazimah 2020 年 6 月 15 日
コメント済み: Ameer Hamza 2020 年 6 月 15 日
there are 2 equations dx/dt = 0.5x-0.01xy ; dy/dt = -0.5y+0.01xy ; How to plot (t,y) and (t,x) together? With t[0-40] and x(t=0)=80 ; y(t=0)=100

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 6 月 15 日
See ode45()
tspan = [0, 40];
ic = [80; 100];
[t, Z] = ode45(@odeFun, tspan, ic);
x = Z(:,1); % x solution
y = Z(:,2); % y solution
hold on
plot(t, x, 'ro-');
plot(t, y, 'bv-');
legend({'x', 'y'})
function dZdt = odeFun(t, Z)
% Z(1) => x, Z(2) => y
x = Z(1);
y = Z(2);
dxdt = 0.5*x - 0.01*x*y;
dydt = -0.5*y + 0.01*x*y;
dZdt = [dxdt; dydt];
end
  2 件のコメント
Az Zahra Hazimah
Az Zahra Hazimah 2020 年 6 月 15 日
Thankyouuuuuu so much!!!
Ameer Hamza
Ameer Hamza 2020 年 6 月 15 日
I am glad to be of help!

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by