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);
Error using contourf
Z must be at least a 2x2 matrix.
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
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
Codex 2023 年 10 月 30 日
My aim is to have contour plot (R0 against some parameters) in this image representation:
Dyuman Joshi
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
Codex 2023 年 10 月 30 日
Thanks so much for your response.
How can I represent that or can you help with it
Dyuman Joshi
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
Codex 2023 年 10 月 30 日
R_0 represent basic reproduction number.
alpha_1 = 0.01; %Modification parameters in reducing transmission
alpha_3 = 1.5; %Modification parameters in reducing transmission
This is to investigate the relation of the basic reproduction number (R_0) against the alpha_1 and alpha_3. And it can be R_0 against beta_mm
Dyuman Joshi
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 件)

Walter Roberson
Walter Roberson 2023 年 10 月 30 日

0 投票

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);
Name Size Bytes Class Attributes I_f 1x1 8 double I_m 1x1 8 double R_0 21x7 1176 double alpha_1 21x7 1176 double alpha_2 1x1 8 double alpha_3 21x7 1176 double alpha_f 1x1 8 double alpha_m 1x1 8 double beta_ff 1x1 8 double beta_fm 1x1 8 double beta_mf 1x1 8 double beta_mm 1x1 8 double cmdout 1x33 66 char levels 1x7 56 double tau_f 1x1 8 double tau_m 1x1 8 double
[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)

カテゴリ

質問済み:

2023 年 10 月 30 日

編集済み:

2023 年 11 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by