Graphing several curves of a variable for various values of a parameter
3 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Gamma Functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!