I want to colour the area between red line and black line below the intersection point. how am i going to do it?

1 Ansicht (letzte 30 Tage)
I want to colour the area between red line and black line below the intersection point. how am i going to do it?
c=[3,5];
A=[1,2;1,1;0,1];
b=[2000;1500;600];
y1=0:1:max(b);
x21=(b(1)-A(1,1)*y1)./A(1,2);
x22=(b(2)-A(2,1)*y1)./A(2,2);
x23=(b(3)-A(3,1)*y1)./A(3,2);
plot(y1,x21,'r',y1,x22,'k',y1,x23,'b');

Antworten (2)

Chunru
Chunru am 28 Nov. 2021
c=[3,5];
A=[1,2;1,1;0,1];
b=[2000;1500;600];
y1=0:1:max(b);
x21=(b(1)-A(1,1)*y1)./A(1,2);
x22=(b(2)-A(2,1)*y1)./A(2,2);
x23=(b(3)-A(3,1)*y1)./A(3,2);
plot(y1,x21,'r',y1,x22,'k',y1,x23,'b');
hold on
fill( [y1(end:-1:993)'; y1(993:end)'; ], [x22(end:-1:993)'; x21(993:end)'], 'y' )

Star Strider
Star Strider am 28 Nov. 2021
Use ‘logical indexing’ to identify & fill the appropriate area —
c=[3,5];
A=[1,2;1,1;0,1];
b=[2000;1500;600];
y1=0:1:max(b);
x21=(b(1)-A(1,1)*y1)./A(1,2);
x22=(b(2)-A(2,1)*y1)./A(2,2);
x23=(b(3)-A(3,1)*y1)./A(3,2);
figure
plot(y1,x21,'r',y1,x22,'k',y1,x23,'b');
hold on
Lv = x21 >= x22; % Logical Index To Selecet Vector Segments
patch([y1(Lv) flip(y1(Lv))], [x21(Lv) flip(x22(Lv))], 'g') % Use 'Lv' With 'patch' To Fill The Required Region
hold off
This approach can easily be used to fill other areas of the plot, as required. This requires one indexing line to create ‘Lv’ and one patch call.
.

Kategorien

Mehr zu Problem-Based Optimization Setup finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by