3d function domain problem

3 views (last 30 days)
Nathan Shapiro
Nathan Shapiro on 3 Oct 2020
Answered: madhan ravi on 3 Oct 2020
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

Answers (1)

madhan ravi
madhan ravi on 3 Oct 2020

Products

Community Treasure Hunt

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

Start Hunting!

Translated by