The code is plotting $R_0$ against two parameters
古いコメントを表示
I have been trying to run this code but it give me this error:
Error in Testing_1 (line 21)
[c,h] = contourf(alpha_3,alpha_1,R_0',levels);
%Basic Reproduction Number
alpha_m = 1/8.5; %Rate at which exposed men respectively become infectious
alpha_f = 1/22; %Rate at which exposed women respectively become infectious
tau_m = 1/8.5; %Rate at which infectious men respectively recover
tau_f = 1/21; %Rate at which infectious women respectively recover
beta_mm = 0.23; %Transmission probability from infectious men having sex with susceptible men
beta_ff = 0.18; %Transmission probability from infectious women having sex with susceptible women
beta_mf = 0.01; %Transmission probability from infectious men having sex with susceptible women
beta_fm = 0.18; %Transmission probability from infectious women having sex with susceptible men
alpha_1 = 0.01; %Modification parameters in reducing transmission
alpha_2 = 0.1; %Modification parameters in reducing transmission
alpha_3 = 1.5; %Modification parameters in reducing transmission
I_f = 27; %Population of infectious women
I_m = 28.22; %Population of infectious men
R_0 = (alpha_3 * beta_ff * tau_m + beta_mm * tau_f)/(2 * tau_f * tau_m) + sqrt(4*alpha_1*alpha_2*beta_fm*beta_mf*tau_f*tau_m + alpha_3^2*beta_ff^2*tau_m^2 - 2*alpha_3 * beta_ff * beta_mm * tau_f * tau_m + beta_mm^2 * tau_f^2)/(2 * tau_f * tau_m);
% plot
levels = (0:0.2:1.2);
[c,h] = contourf(alpha_3,alpha_1,R_0',levels);
clabel(c,h)
h.LineWidth = 2; % contour line width (up to you)
xlabel('\alpha_3');
ylabel('\alpha_1');
colormap(jet(numel(levels)-1));
colorbar('vert');
I will appreciate a response.
7 件のコメント
Dyuman Joshi
2023 年 10 月 30 日
編集済み: Dyuman Joshi
2023 年 10 月 30 日
As the error clearly states, Z i.e. the 3rd input to contourf in the syntax used, should be atleast a 2x2 matrix.
In your case it isn't, it's 1x1.
Codex
2023 年 10 月 30 日
Dyuman Joshi
2023 年 10 月 30 日
For that, you will need x and y parameters that vary as well.
The x and y parameters you have (alpha3 and alpha1) are singular.
Codex
2023 年 10 月 30 日
Dyuman Joshi
2023 年 10 月 30 日
I do not know what you are trying to do. The comments tell what each parameter is, but does not give an overall idea as to what the objective is.
So, what is the objective?
What does R_0, alpha1 and alpha3 represent?
Codex
2023 年 10 月 30 日
Dyuman Joshi
2023 年 11 月 24 日
編集済み: Dyuman Joshi
2023 年 11 月 24 日
It's not possible to draw a surface plot with scalar data.
You can see that in the answer below, Walter has defined alpha_1 and alpha_3 as grids, only then a surface plot is obtained.
Are you using a research paper as reference and trying to reproduce some results? If so, then please share additional information regarding it.
回答 (1 件)
I had to guess about the range of alpha_1 and alpha_3 that you wanted to plot.
The contour turns out solid color because the values of R_0 are mostly more than max(levels)
The surface is pretty boring except for a small area near the origin. And if you go too far from the origin then there is a part where the surface goes complex valued. So you would need to tell us what plot range to look at.
%Basic Reproduction Number
alpha_m = 1/8.5; %Rate at which exposed men respectively become infectious
alpha_f = 1/22; %Rate at which exposed women respectively become infectious
tau_m = 1/8.5; %Rate at which infectious men respectively recover
tau_f = 1/21; %Rate at which infectious women respectively recover
beta_mm = 0.23; %Transmission probability from infectious men having sex with susceptible men
beta_ff = 0.18; %Transmission probability from infectious women having sex with susceptible women
beta_mf = 0.01; %Transmission probability from infectious men having sex with susceptible women
beta_fm = 0.18; %Transmission probability from infectious women having sex with susceptible men
%alpha_1 = 0.01; %Modification parameters in reducing transmission
alpha_2 = 0.1; %Modification parameters in reducing transmission
%alpha_3 = 1.5; %Modification parameters in reducing transmission
I_f = 27; %Population of infectious women
I_m = 28.22; %Population of infectious men
% plot
levels = (0:0.2:1.2);
[alpha_1, alpha_3] = meshgrid(0:0.005:0.03, 1:0.05:2);
R_0 = (alpha_3 .* beta_ff .* tau_m + beta_mm .* tau_f)./(2 .* tau_f .* tau_m) + sqrt(4 .* alpha_1 .* alpha_2 .* beta_fm .* beta_mf .* tau_f .* tau_m + alpha_3.^2 .* beta_ff.^2 .* tau_m.^2 - 2 .* alpha_3 .* beta_ff .* beta_mm .* tau_f .* tau_m + beta_mm.^2 .* tau_f.^2) ./ (2 .* tau_f .* tau_m);
[c,h] = contourf(alpha_3,alpha_1,R_0,levels);
clabel(c,h)
h.LineWidth = 2; % contour line width (up to you)
xlabel('\alpha_3');
ylabel('\alpha_1');
colormap(jet(numel(levels)-1));
colorbar('vert');
figure()
surf(alpha_3,alpha_1,R_0);
view(3)
カテゴリ
ヘルプ センター および File Exchange で Ordinary Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


