How can I plot in 2D space the projection of area satisfied by inequalities in 3D space and also colour the area as a colour gradient with respect to the values of the Z variable?

1 次查看(过去 30 天)
x+2y+4z > -20 ; x+z < -2.5 ; 2y+3z <-17 ;
I have the above inequalities and I need to plot the area satisfied by these inequalities in 2D space. Then I need to have the area coloured in a gradient which will correspond to the z values. Any idea how to do this? I want a figure similar to the one I have attached. Thanks!

采纳的回答

Sam Cook
Sam Cook 2018-6-13
You could create a scatter plot of points that satisfy your equations, and color them based on the Z values.
range = -5:0.02:5;
lr = length(range);
[X, Y, Z] = meshgrid(range, range, range); % Points to check
ineq1 = X + 2*Y + 4*Z > -20; % Define the inequalities
ineq2 = X + Z < -2.5;
ineq3 = 2*Y + 3*Z < -17;
conditions = ineq1 & ineq2 & ineq3;
nX = X(conditions); % Get the points that satisfy them
nY = Y(conditions);
nZ = Z(conditions);
scatter(nX, nY, 10, nZ, 'filled'); % Plot the points, colored according to Z values
colorbar
grid on
Because the equations produce 3D surfaces (rather than lines in 3D space), you

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Scatter Plots 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by