
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?
조회 수: 6 (최근 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!
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!