
How do I change the axis of my plot of the SIR model?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Arata Kaizaki
le 8 Mar 2020
Modifié(e) : Ameer Hamza
le 9 Mar 2020
Hello, I'm currently working on an SIR model and plotting them. However, my y-axis shows up as a range from 0 to 1, instead of 0 to the population I am using. I've tried to play around with the y-axis, but it drastically changes my plots. How do I render the y-axis from 0 to the population I am testing without effecting how it is plotted?
My code is shown below:
N = 59170000;
I = 67466;
R = 40592;
S = N - I - R;
s = S/N;
i = I/N;
r = R/N;
props = [s i r];
[t,x] = ode45('sir', [0 365], props);
plot(t,x,'LineWidth',2);
xlim([0 365]);
xticks(0:20:365);
legend('S','I','R','Location','best');
This is my SIR function:
function dx = sir(t, x)
dx = [0; 0; 0];
r0 = 2.28;
gamma = 1/18;
beta = r0*gamma;
dx(1) = -beta * x(1) * x(2);
dx(2) = beta * x(1) * x(2) - gamma * x(2);
dx(3) = gamma * x(2);
end
0 commentaires
Réponse acceptée
Ameer Hamza
le 8 Mar 2020
I get the following plot when I run your code.

The x-axis is from 0 to 360, as expected from xlim([0 365]). What do you expect different.
2 commentaires
Ameer Hamza
le 9 Mar 2020
Modifié(e) : Ameer Hamza
le 9 Mar 2020
If you just want to show y-axis from 0 to n (say 10), you can add
ylim([0 10]);
However, how you want to scale your whole graph, you can multiply the matrix by 10 (or any value n)
[t,x] = ode45('sir', [0 365], props);
plot(t,10*x,'LineWidth',2);
xlim([0 365]);
xticks(0:20:365);
legend('S','I','R','Location','best');
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!