Plotting multiple inequalities in 3D Space

조회 수: 8 (최근 30일)
Patrick Dotson
Patrick Dotson 2021년 11월 23일
답변: John D'Errico 2021년 11월 23일
Hi, I wanted to plot a set of points in 3d space in Matlab subject to multiple inequalities. I tried doing this:
[x,y,x] = meshgrid(-10:0.1:10);
ineq = [0<=y, y<=3, 9-y.^2<=x, x<=9, 0<=z, z<=9-x]
x(~ineq) = NaN;
y(~ineq) = NaN;
z(~ineq) = NaN;
surf(x,y,z)
But I am told that I "Attempted to grow array along ambiguous dimension." I was wondering what the correct way to do this would be.

채택된 답변

John D'Errico
John D'Errico 2021년 11월 23일
First,
[x,y,x] = meshgrid(-10:0.1:10);
Correct code is important in MATLAB. Else it will not know that you really intended to write [x,y,z] and not [x,y,x].
Next, what do you think this does?
ineq = [0<=y, y<=3, 9-y.^2<=x, x<=9, 0<=z, z<=9-x]
It does not create something that is "and"ed across those inequaities. Instead, it creates a larger array.
Next, is the result of that operation actually a surface, or just something that you want to interpret as a surface?
surf(x,y,z)
So how can surf possibly interpret what it will see as a set of scattered points, some of which are NaNs, and know what you intend?
You MIGHT try this:
[x,y,z] = meshgrid(-10:0.1:10,-10:0.1:10,-10:0.1:10);
ineq = (0<=y) & (y<=3) & (9-y.^2<=x) & (x<=9) & (0<=z) & (z<=9-x);
x(~ineq) = NaN;
y(~ineq) = NaN;
z(~ineq) = NaN;
plot3(x(:),y(:),z(:),'.')
view(-15,65)
box on
grid on
But all that does is show a non-convex domain, represented by scattered data points that lie inside the domain. Surf is not designed to do what you want.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by