Contour plot of R_0 against one parameter and two parameters.
1 回表示 (過去 30 日間)
古いコメントを表示
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)
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');
0 件のコメント
回答 (1 件)
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).
Refer this doc: https://in.mathworks.com/help/matlab/ref/meshgrid.html
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
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');
参考
カテゴリ
Help Center および File Exchange で Surface and Mesh Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!