Plotting Set of Inequalities

7 views (last 30 days)
Michael
Michael on 21 Jul 2025
Edited: Matt J on 21 Jul 2025
I am working with a set of inequalities:
1)
2)
3)
I can't figure out how to plot it nicely on a 3d graph. The way I have it now, it's all lines, so the actual solutions are not clear.
clear;clc;close all
%{
x_1 = X
x_2 = Y
x_3 = Z
%}
X = [0:1:400];
Y = [0:1:400];
Z = [0:1:400];
% EQ 1A
cond1 = 2.*X;
%EQ 1B
cond2 = 3.*X;
%EQ 2A
xline(150)
%EQ 2B
xline(280)
cond5 = 173 + Y;
cond6 = 20 + Y;
plot3(X,cond1,Z,'DisplayName',"cond1")
hold on
plot3(X,cond2,Z,'DisplayName',"cond2")
hold on
plot3(X,Y,cond5,'DisplayName',"cond5")
hold on
plot3(X,Y,cond6,'DisplayName',"cond6")
hold on
xline(14)
xline(298)
grid on
grid minor
xlabel("x_1")
ylabel("x_2")
zlabel("x_3")
legend
box on

Answers (2)

Star Strider
Star Strider on 21 Jul 2025
It is difficulf for me to interpret what you want to plot.
One way to 'include' an area of inequality in a plot is to use the patch function. I have done this once here to demonstrate the approach, however you will need to make any necessary corrections to my single patch call, and then add your own for the other conditions.
Try something like this --
clear;clc;close all
%{
x_1 = X
x_2 = Y
x_3 = Z
%}
X = [0:1:400];
Y = [0:1:400];
Z = [0:1:400];
% EQ 1A
cond1 = 2.*X;
%EQ 1B
cond2 = 3.*X;
%EQ 2A
xline(150)
%EQ 2B
xline(280)
cond5 = 173 + Y;
cond6 = 20 + Y;
plot3(X,cond1,Z,'DisplayName',"cond1")
patch([X flip(X)], [zeros(size(cond1)) flip(cond1)], [Z flip(Z)], 'r', DisplayName='cond1 inequality region')
hold on
plot3(X,cond2,Z,'DisplayName',"cond2")
hold on
plot3(X,Y,cond5,'DisplayName',"cond5")
hold on
plot3(X,Y,cond6,'DisplayName',"cond6")
hold on
xline(14)
xline(298)
grid on
grid minor
xlabel("x_1")
ylabel("x_2")
zlabel("x_3")
legend
box on
.

Matt J
Matt J on 21 Jul 2025
Edited: Matt J on 21 Jul 2025
Your inequalities can be re-arranged as linear inequalities,
and then plotted using this FEX download,

Community Treasure Hunt

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

Start Hunting!