Mesh plot of the function sqrt(y-x^2)
Show older comments
I want to plot the function
The function is defined for
. With
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?
Accepted Answer
More Answers (1)
Bruno Luong
on 6 Apr 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)

Categories
Find more on Line 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!
