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

3 ビュー (過去 30 日間)
Arata Kaizaki
Arata Kaizaki 2020 年 3 月 8 日
編集済み: Ameer Hamza 2020 年 3 月 9 日
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

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 3 月 8 日
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 件のコメント
Arata Kaizaki
Arata Kaizaki 2020 年 3 月 8 日
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 2020 年 3 月 9 日
編集済み: Ameer Hamza 2020 年 3 月 9 日
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');

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by