How to plot all contour lines in one plot?

์กฐํšŒ ์ˆ˜: 5 (์ตœ๊ทผ 30์ผ)
Jorge Arturo Clares Pastrana
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

์ฑ„ํƒ๋œ ๋‹ต๋ณ€

Star Strider
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
Jorge Arturo Clares Pastrana
Jorge Arturo Clares Pastrana 2022๋…„ 3์›” 15์ผ
Thnakyou.
z = -4*x - 2*y - x^2 + 2*x^4 - 2*x*y + 3*y^2;
when i input the following equation for z it outputs a blank post do you know why?
Star Strider
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๊ฐœ)

Jorge Arturo Clares Pastrana
Jorge Arturo Clares Pastrana 2022๋…„ 3์›” 15์ผ
Thnakyou.
z = -4*x - 2*y - x^2 + 2*x^4 - 2*x*y + 3*y^2;
when i input the following equation for z it outputs a blank post do you know why?

์นดํ…Œ๊ณ ๋ฆฌ

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!

Translated by