Plotting contour lines at specific value

I have two functions f1 and f2 defined as follows:
f1(x) = x_1^2 + x_2^2 - 4
f2(x) = 5(x_1 - 1)^2 - x_2 - 3
where x = (x_1,x_2)^T.
Now I want to plot the contour lines of these functions at value 0, that is, I want to plot the functions
x_1^2 + x_2^2 - 4 = 0
5(x_1 - 1)^2 - x_2 - 3 = 0
I tried using contourplot, but no luck there. Is there a smarter way, for example using Linspace?

 Respuesta aceptada

Matt Fig
Matt Fig el 24 de Mzo. de 2011
Please re-paste your code and use the code format button so we can read it. I see a bunch of ? marks in the code.
When using the CONTOUR function, you can provide an argument which tells the function where to draw the contours.
Here is a way to get a surface and contours in one plot:
[x_1,x_2] = meshgrid(-10:.1:10,-10:.1:10);
f1 = @(x_1,x_2) x_1.^2 + x_2.^2 - 4;
f2 = @(x_1,x_2) 5*(x_1 - 1).^2 - x_2 - 3;
subplot(2,1,1)
surfc(x_1,x_2,f1(x_1,x_2))
subplot(2,1,2)
surfc(x_1,x_2,f2(x_1,x_2))
To get just the surface, use the SURF function.

6 comentarios

David
David el 24 de Mzo. de 2011
I can only see contour(X,Y,Z,n), where n is the number of lines, not there specific z-value.
Matt Fig
Matt Fig el 24 de Mzo. de 2011
From the documentation:
CONTOUR(Z,V) and CONTOUR(X,Y,Z,V) draw LENGTH(V) contour lines
at the values specified in vector V. Use CONTOUR(Z,[v v]) or
CONTOUR(X,Y,Z,[v v]) to compute a single contour at the level v.
David
David el 24 de Mzo. de 2011
I have no idea how I missed that option. Is there a simpler way to do this, if for example if I just wanted to plot the curve
x_1^2 + x_2^2 - 4 = 0
Is it possible to plot the curve, without using contourplot?
Matt Fig
Matt Fig el 24 de Mzo. de 2011
See my answer above.
Mohammad Sohail
Mohammad Sohail el 30 de Mayo de 2017
@David try this
syms x y
ezplot(x^2+y^2-4)
Avinash Kumar
Avinash Kumar el 9 de Abr. de 2019
thanks

Iniciar sesión para comentar.

Más respuestas (1)

kanekal kullayappa
kanekal kullayappa el 24 de Feb. de 2014

0 votos

hello sir, I need the function to obtain the plots in the joint tdoa and aoa location algorithm http://www.jseepub.com/EN/article/downloadArticleFile.do?attachType=PDF&id=11834.

Etiquetas

Preguntada:

el 24 de Mzo. de 2011

Comentada:

el 9 de Abr. de 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by