Plotting multiple inequalities in 3D Space

2 次查看(过去 30 天)
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 个)

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by