Contour plot of R_0 against one parameter and two parameters.

1 回表示 (過去 30 日間)
BURHANUDDIN SAFI
BURHANUDDIN SAFI 2024 年 6 月 3 日
コメント済み: BURHANUDDIN SAFI 2024 年 6 月 3 日
Hello everyone,
I am trying to plot contour of R_0 against one and two parameters, I checked the code few times but been unable to detect where actually the error is. Can anyone please help me with plotting R_0 against one and two parameters?
clear, clc, close
% Define the variables
b = 0.19408;
d = 0.957163;
d1 = 0.078622871;
alpha = 0:0.1:1;
gamma = 0:0.1:1;
% The basic reproduction number R_0
R_0 = alpha.*b./ (d^2 + d * d1 + d * gamma);
% Plotting the contour of R_0 against alpha
levels = 0:0.1:1;
contourf(alpha, R_0, levels)
Error using contourf (line 57)
Z must be at least a 2x2 matrix.
colorbar('vert');
xlabel('\alpha');
ylabel('\gamma');
title('Contour Plot of R_0 vs. \alpha');
% Ploting the contour of R_0 against alpha and gamma
contourf(alpha, gamma, R_0, levels)
colorbar('vert');
xlabel('\alpha');
ylabel('\gamma');
title('Contour Plot of R_0 vs. \alpha and \gamma');

回答 (1 件)

Manikanta Aditya
Manikanta Aditya 2024 年 6 月 3 日
The error you’re encountering is because the contourf function in MATLAB expects a 2D matrix for its second argument, but you’re providing a 1D array. The contourf function is used to create a filled contour plot containing the isolines of matrix Z, where Z contains height values on the x-y plane.
In your case, you’re trying to plot R_0 which is a function of alpha and gamma. Therefore, R_0 should be a 2D matrix where each element R_0(i, j) corresponds to the value of the function at alpha(i) and gamma(j).
clear, clc, close
% Define the variables
b = 0.19408;
d = 0.957163;
d1 = 0.078622871;
alpha = 0:0.1:1;
gamma = 0:0.1:1;
[Alpha, Gamma] = meshgrid(alpha, gamma); % Create a grid of alpha and gamma values
% The basic reproduction number R_0
R_0 = Alpha.*b./ (d^2 + d * d1 + d * Gamma); % Compute R_0 for each pair of alpha and gamma
% Plotting the contour of R_0 against alpha and gamma
levels = 0:0.1:1;
contourf(Alpha, Gamma, R_0, levels)
colorbar('vert');
xlabel('\alpha');
ylabel('\gamma');
title('Contour Plot of R_0 vs. \alpha and \gamma');
This should help!
  2 件のコメント
Manikanta Aditya
Manikanta Aditya 2024 年 6 月 3 日
clear, clc, close
% Define the variables
b = 0.19408;
d = 0.957163;
d1 = 0.078622871;
alpha = 0:0.1:1;
gamma = 0:0.1:1;
% The basic reproduction number R_0
R_0_alpha = alpha.*b./ (d^2 + d * d1 + d * gamma);
% Plotting the contour of R_0 against alpha
figure; % Create a new figure
plot(alpha, R_0_alpha);
xlabel('\alpha');
ylabel('R_0');
title('Plot of R_0 vs. \alpha');
BURHANUDDIN SAFI
BURHANUDDIN SAFI 2024 年 6 月 3 日
Thank you so much sir

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

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by