필터 지우기
필터 지우기

How to plot 2D Linear Inequality?

조회 수: 2 (최근 30일)
Omar B.
Omar B. 2021년 9월 17일
댓글: Omar B. 2021년 9월 17일
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
...

채택된 답변

KSSV
KSSV 2021년 9월 17일
[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
KSSV
KSSV 2021년 9월 17일
Coordinates of contour lines are obtained. Those are c1, c2. These coordinates are row arrays. c1(1,:) means first row which is x -coordinate and c1(2,:) is second row which is y-coordinate.
Omar B.
Omar B. 2021년 9월 17일
I got it. Thank you so much.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Denoising and Compression에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by