How to plot all contour lines in one plot?
์กฐํ ์: 5 (์ต๊ทผ 30์ผ)
์ด์ ๋๊ธ ํ์
Jorge Arturo Clares Pastrana
2022๋
3์ 15์ผ
๋๊ธ: Star Strider
2022๋
3์ 15์ผ
Giiven a function f(x) I need to Plot the level sets contour lines where ๐(x) = โ4.34, โ4.3, โ4.2, โ4.1, โ4, โ3, โ2, โ1, 0.
Plot all of them in one graph
๋๊ธ ์: 0
์ฑํ๋ ๋ต๋ณ
Star Strider
2022๋
3์ 15์ผ
Specify them as a single levels vector โ
[X, Y, Z] = peaks(50);
figure
contour(X, Y, Z, [-4.34, -4.3, -4.2, -4.1, -4, -3, -2, -1, 0], 'ShowText',1)
colormap(turbo)
.
๋๊ธ ์: 2
Star Strider
2022๋
3์ 15์ผ
First, the function needs to be vectorised so that it can do element-wise calculations. Otherwise, it could be because for the values of โxโ and โyโ you are using, โzโ has no values in the range of the desired contours. Also, โxโ and โyโ must be matrices, not vectors, although I suspect that would throw a specific error.
Use your values for โxโ and โyโ in something like this example code โ
z = @(x,y) -4*x - 2*y - x.^2 + 2*x.^4 - 2*x.*y + 3*y.^2; % Vectorised Anonymous Function For 'z'
x = linspace(-5, 5, 150);
y = linspace(-5, 5, 150);
[X,Y] = ndgrid(x, y);
Z = z(X,Y);
figure
contour(X, Y, Z, [-4.34, -4.3, -4.2, -4.1, -4, -3, -2, -1, 0], 'ShowText',1)
colormap(turbo)
axis([-1 2 -1 2])
.
์ถ๊ฐ ๋ต๋ณ (1๊ฐ)
์ฐธ๊ณ ํญ๋ชฉ
์นดํ ๊ณ ๋ฆฌ
Help Center ๋ฐ File Exchange์์ Contour Plots์ ๋ํด ์์ธํ ์์๋ณด๊ธฐ
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

