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 view (last 30 days)
Show older comments
Mohammed Ishfaque Elias
on 6 Jun 2018
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!
0 Comments
Accepted Answer
Sam Cook
on 13 Jun 2018
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 Comments
More Answers (0)
See Also
Categories
Find more on Scatter Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!