Borrar filtros
Borrar filtros

Mesh plot of the function sqrt(y-x^2)

4 visualizaciones (últimos 30 días)
Dimitrios Anagnostou
Dimitrios Anagnostou el 6 de Abr. de 2021
Comentada: Star Strider el 6 de Abr. de 2021
I want to plot the function The function is defined for . With
f = @(x,y)sqrt(y-x.^2);
fmesh(f,[-3 3 0 9])
I get a mesh plot of the function in the rectangle [-3,3]X[0,9]. I want to plot the function using meshgrid. The following code results to complex values error message.
x = -3:1:3
y = 0:1:9
[X, Y] = meshgrid(x,y)
Z = sqrt(Y-X.^2)
mesh(X,Y,Z)
The problem is that Z is evaluated for not suitable pairs of (X,Y). What am I doing wrong?

Respuesta aceptada

Star Strider
Star Strider el 6 de Abr. de 2021
Editada: Star Strider el 6 de Abr. de 2021
Try this:
x = -3:1:3;
y = 0:1:9;
[X, Y] = meshgrid(x,y);
Y = Y.*(Y>=X.^2); % Select Y ≥ X^2
Z = sqrt(Y-X.^2);
Zre = Z.*(imag(Z)==0); % Select Only Real Values Of ‘Z’
figure
mesh(X,Y,Zre)
EDIT — (5 Apr 2021 at 15:56)
Added:
Y = Y.*(Y>=X.^2); % Select Y ≥ X^2
to accord with the edited Question.
  5 comentarios
Dimitrios Anagnostou
Dimitrios Anagnostou el 6 de Abr. de 2021
So, I guess, the easiest solution is to use fmesh here:-)! Thank your very much for your feedback. I was puzzled today during a lesson how to have mesh return a similar graph with fmesh.
Star Strider
Star Strider el 6 de Abr. de 2021
As always, my pleasure!
The easiest solution is to use fmesh. It is possible to examine the fmesh code using edit or type (however that is not very revealing, since it calls fsurf, that it is posible to examine in some detail) to see exactly how it works. The fsurf function then calls a number of other funcitons that I have not taken the time to examine closely. My information on the ‘f’ plotting functions derives from other discussions in MATLAB Central that I have read over the years.

Iniciar sesión para comentar.

Más respuestas (1)

Bruno Luong
Bruno Luong el 6 de Abr. de 2021
Here is the surface in meshgrid form
s = -1:0.01:1;
y = 0:0.1:9;
[S, Y] = meshgrid(s,y);
X = S.*sqrt(Y);
Z = sqrt(max(Y-X.^2,0));
figure
mesh(X,Y,Z)

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by