Contour plot of R_0 against one parameter and two parameters.
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Manikanta Aditya
il 3 Giu 2024
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 Commenti
Manikanta Aditya
il 3 Giu 2024
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');
Vedere anche
Categorie
Scopri di più su Surface and Mesh Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!