フィルターのクリア

Graphing several curves of a variable for various values of a parameter

2 ビュー (過去 30 日間)
Bas123
Bas123 2023 年 3 月 27 日
コメント済み: Bas123 2023 年 3 月 27 日
I am trying to produce a graph like the one below for an SIR model.
In particular, I would like to draw five plots of the variable I (denoted in the code as y(2) for the values of beta = (0, 0,2, 0.4, 0.6, 0.8). The code that I used is given below. Any help would be highly appreciated.
%Plotting on command window
[t,y] = ode23s(@SIR_Model, [0 180], [1 1.13*10^(-5) 0]);
plot(t,y(:,2))
title('Number of infections')
xlabel('t')
ylabel('I')
function dy=SIR_Model(t,y)
%Create an empty vector
dy = zeros(3,1);
%Parameters
beta = 1/3; %transmission coefficient
gamma = 1/4; %recovery rate
%ODES
dy(1) = -beta*y(1)*y(2);
dy(2) = beta*y(1)*y(2) - gamma*y(2);
dy(3) = gamma*y(2);
end

採用された回答

Matt J
Matt J 2023 年 3 月 27 日
編集済み: Matt J 2023 年 3 月 27 日
%Plotting on command window
BETAS=[0, 0.2, 0.4, 0.6, 0.8];
for i=1:numel(BETAS)
beta=BETAS(i);
[t,y] = ode23s(@(t,y) SIR_Model(t,y,beta), [0 180], [1 1.13*10^(-5) 0]);
plot(t,y(:,2)); hold on
end; hold off
legend("Is:"+(1:numel(BETAS)) + "(" + BETAS + ")" )
title('Number of infections')
xlabel('t')
ylabel('I')
function dy=SIR_Model(t,y,beta)
%Create an empty vector
dy = zeros(3,1);
%Parameters
%beta = 1/3; %transmission coefficient
gamma = 1/4; %recovery rate
%ODES
dy(1) = -beta*y(1)*y(2);
dy(2) = beta*y(1)*y(2) - gamma*y(2);
dy(3) = gamma*y(2);
end
  3 件のコメント
Matt J
Matt J 2023 年 3 月 27 日
See what I've done above. I'm not sure exactly how it's supposed to look.
Bas123
Bas123 2023 年 3 月 27 日
Fantastic, thank you so much!

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

その他の回答 (0 件)

カテゴリ

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