MATLAB Answers

How to plot 2D Linear Inequality?

3 views (last 30 days)
Omar B.
Omar B. on 17 Sep 2021
Commented: Omar B. on 17 Sep 2021
How to plot cond1 and cond2 with the cost in one figure?
[x1,x2]=meshgrid(0:.1:10,0:.1:10);
cond1=x1-x2<=-2;
cond2=-0.3*x1-x2<=-8;
cost=0.4*x1.^2-5*x1+x2.^2-6*x2+50;
figure (1)
contour(x1,x2,cost,10,'linewidth',2)
xlabel('x_{1}');
ylabel('x_{2}');
hold on
...

Accepted Answer

KSSV
KSSV on 17 Sep 2021
[x1,x2]=meshgrid(0:.1:10,0:.1:10);
cond1=x1-x2<=-2;
cond2=-0.3*x1-x2<=-8;
cost=0.4*x1.^2-5*x1+x2.^2-6*x2+50;
figure (1)
contour(x1,x2,cost,10,'linewidth',2)
hold on
contour(x1,x2,cond1,'color','k','linewidth',2)
contour(x1,x2,cond2,'color','r','linewidth',2)
xlabel('x_{1}');
ylabel('x_{2}');
hold on
  6 Comments
Omar B.
Omar B. on 17 Sep 2021
I got it. Thank you so much.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!