Plotting multiple inequalities in 3D Space

16 visualizaciones (últimos 30 días)
Patrick Dotson
Patrick Dotson el 23 de Nov. de 2021
Respondida: John D'Errico el 23 de Nov. de 2021
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.

Respuesta aceptada

John D'Errico
John D'Errico el 23 de Nov. de 2021
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.

Más respuestas (0)

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by