3d function domain problem

2 次查看(过去 30 天)
Nathan Shapiro
Nathan Shapiro 2020-10-3
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

回答(1 个)

madhan ravi
madhan ravi 2020-10-3

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by