3d function domain problem
1 view (last 30 days)
Show older comments
When graphing 3d surface functions, how do you limit the points generated by meshgrid to within the domain of the function? For example, in the function z = sqrt(9-x^2-4y^2), the domain is all (x,y) inside or on the ellipse x^2 + 4y^2 = 9. In the code below the best I could do was limit x1 and y1 so that x and y would always be within this ellipse, but I am still missing part of the function. Is there a way to create an elliptical (or other than rectangular) domain for the function?
clear
clc
r=100;
x1 = linspace(-2,2,r);
y2 = linspace(-1.5,1.5,r);
[x,y] = meshgrid(x1,y2);
z=sqrt(9-x.^2-4*y.^2);
figure
mesh(x,y,z)
xlabel('x');
ylabel('y');
zlabel('z');
grid on
0 Comments
Answers (1)
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!