How do I change the axis of my plot of the SIR model?

6 views (last 30 days)
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

Accepted Answer

Ameer Hamza
Ameer Hamza on 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 Comments
Arata Kaizaki
Arata Kaizaki on 8 Mar 2020
I meant that the y-axis isn't showing from 0 to N, but it shows it as from 0 to 1
Ameer Hamza
Ameer Hamza on 9 Mar 2020
Edited: Ameer Hamza on 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');

Sign in to comment.

More Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!