how to draw contour plot
7 views (last 30 days)
Show older comments
good evening sir
sir i have to draw contour plot . i am taking some examples from other papers i am trying to find contour plot but i did not get results sir. please tell me where i had made mistake
the code is
% R0 = x*(1-b)*(1-v)*(u+y+p+t+w)*e/(u*(u+w)*(u+y+p+t))
% b =1.10340
% v =1.03330
% u =0.72936
% p =0.65722
% t =3.04270
% w =0.327688
% e =0.521749
% by substituting all values i got function Ro = x.*(0.00230).*((y+4.7569)/(y+4.442929))
x = linspace(0,0.02,1)
y = linspace(0,0.02,0.04)
[xm,ym] = meshgrid(x,y)
R0 = xm.*(0.00230).*((ym+4.7569)/(ym+4.442929))
contourf(xm,ym,R0)
colorbar
but original figure from other paper is
here alpha c is x and delta is y
i request you sir please help how to get this graph sir
thank you sir
1 Comment
Adam Danz
on 22 Apr 2022
Moving my answer here since there were two additional, excellent answers submitted at the same time.
x = linspace(0,0.02,1)
y = linspace(0,0.02,0.04)
Perhaps what you want is this, below, but it produces the a similar plot to the one in your question. Nevertheless, it's the correct plot given the data. If these results are unexpected, then the calculations in R0 are incorrect and we can't fix that because we don't know what they are supposed to be.
x = 0 : 0.02 : 1
y = 0 : 0.02 : 0.04
R0 = 0.00230*x(:).*((y+4.7569)./(y+4.442929))
contourf(x,y,R0')
colorbar
Answers (3)
Davide Masiello
on 22 Apr 2022
Edited: Davide Masiello
on 22 Apr 2022
The problem was in your use of linspace
x = linspace(0,0.05,100);
y = linspace(0,1,100);
[xm,ym] = meshgrid(x,y);
R0 = xm.*(0.00230).*((ym+4.7569)./(ym+4.442929));
contourf(xm,ym,R0)
colorbar
2 Comments
Voss
on 22 Apr 2022
There are a couple of problems.
First is the use of linspace. The arguments to linspace are (min value, max value, number of points), not (min value, spacing, max value), which is how the colon operator works.
Second is that you should use element-wise division ./ rather than matrix division / in your calculation of R0.
% x = linspace(0,0.02,1);
x = linspace(0,1,51);
% y = linspace(0,0.02,0.04);
y = linspace(0,0.04,3);
[xm,ym] = meshgrid(x,y);
% R0 = xm.*(0.00230).*((ym+4.7569)/(ym+4.442929))
R0 = xm.*(0.00230).*((ym+4.7569)./(ym+4.442929));
contourf(xm,ym,R0)
colorbar
(Also, judging by the picture you attached, you may need to rethink which variables are which in your code, since delta goes from 0 to 1 and alpha_c goes from 0 to ~0.05 in the picture.)
0 Comments
Steven Lord
on 22 Apr 2022
There are a couple potential problems here. Did you really mean to make x a 1-element vector or did you mean to go from 0 to 1 in steps of 0.02? In the latter case use the colon operator :.
x = linspace(0,0.02,1) % Original
x_original = x; % Store for later use
x = 0:0.02:1 % I added this
Similarly for y did you mean you wanted a vector with 0.04 elements between 0 and 0.02 or did you want 0.02 to be the spacing?
y = linspace(0,0.02,0.04) % Original
y_original = y; % Store for later use
y = 0:0.02:0.04 % I added this
With your original x and y, xm and ym were empty and therefore so was R0. With the updated x and y they aren't empty.
[xm_original, ym_original] = meshgrid(x_original, y_original)
[xm,ym] = meshgrid(x,y)
You probably want to use element-wise division instead of matrix division in your calculation of R0. Here's your original R0 code operating on your original xm and ym variables.
R0_original = xm_original.*(0.00230).*((ym_original+4.7569)/(ym_original+4.442929))
With the updated xm and ym and using element-wise division the new R0 is not empty.
R0_element = xm.*(0.00230).*((ym+4.7569)./(ym+4.442929));
size(R0_element)
Let's visualize the two R0 arrays. Since R0_original is empty the first surface plot is pretty boring.
figure
surf(xm_original, ym_original, R0_original);
title('R0\_original with matrix division')
The one for R0_element isn't so boring.
figure
surf(xm, ym, R0_element);
title('R0\_element with element-wise division')
Now let's look at the contour plot. You're probably going to want to specify the contour levels of your choice.
figure
contourf(xm, ym, R0_element)
See Also
Categories
Find more on Contour Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!