How can I manually fill in colors (or shade) a part of a feasible region?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
How to shade part of a graph with colors?
I have tried using something like this (look at the very last figure):
[A B] = meshgrid(-2:0.01:2.5,-2:0.01:2.5);
F = 100*(B-A.^2).^2+(1-A)^2;
surf(A,B,F,'EdgeColor','none')
shading flat,view(2)
C1 = A.*B>=1;
F1=F;
F1(~C1)=NaN;
figure, surf(A,B,F1,'EdgeColor','none')
shading flat,view(2)
C2 = A+B.^2 >=0;
F2=F1;
F2(~C2)=NaN;
figure, surf(A,B,F2,'EdgeColor','none')
shading flat,view(2)
C3 = A<=4.5;
F3=F2;
F3(~C3)=NaN;
figure, p1=surf(A,B,F3,'EdgeColor','none')
shading flat,view(2)
hold on
f = @(x1,x2) 100*(x2-(x1).^2).^2+(1-x1).^2;
g1 = @(x1,x2) 1-(x1.*x2);g2 = @(x1,x2) -x1-(x2).^2;g3=@(x1,x2) x1-4.5;
circle_x=0:0.00001:2;
t = (-1:0.00001:1)'*pi;
%circle_y=sqrt(1-(circle_x -2).^2 );
X_double=[X{:}];
ezplot(g1,[-2,2.5,-2,2.5])
hold on
ezplot(g2,[-2,2.5,-2,2.5])
hold on
p2=ezcontour(f,[-2,2.5,-2,2.5])
p3=plot(1,1,'ro');
hold on
p4=plot(X_double(1,:),X_double(2,:),'-k.','MarkerSize',10)
hold on
% CIRCLES OF RAD radius AND CENTERED AT (1,1)
for l=1:5
radius=1/10^(l-1);
x = radius*cos(t) +1;
y = radius*sin(t) +1;
plot(x,y,':k','MarkerSize',100)
hold on
end
ezplot(g3,[-2,2.5,-2,2.5])
hold on
legend([p1 p2 p3 p4],'Feasible Region','f contours','minimum','sequence approaching x*');
title('Feasible Region, contour map and minimizer for Test 2');
hold off
, however, the options for shading (flat, faceted or interp) are hiding some of the the circles and points .I believe it is because the colors are too heavy maybe?, so that is why I wanted to see if there was another way of coloring or shading a specific part of a graph (for instance, I would chose a light color, that would allow me to see all the circles and lines).
I also tried using just this:
f = @(x1,x2) 100*(x2-(x1).^2).^2+(1-x1).^2;
g1 = @(x1,x2) 1-(x1.*x2);g2 = @(x1,x2) -x1-(x2).^2;g3=@(x1,x2) x1-4.5;
circle_x=0:0.00001:2;
t = (-1:0.00001:1)'*pi;
%circle_y=sqrt(1-(circle_x -2).^2 );
X_double=[X{:}];
ezplot(g1,[-2,2.5,-2,2.5])
hold on
ezplot(g2,[-2,2.5,-2,2.5])
hold on
p2=ezcontour(f,[-2,2.5,-2,2.5])
p3=plot(1,1,'ro');
hold on
p4=plot(X_double(1,:),X_double(2,:),'-k.','MarkerSize',10)
hold on
% CIRCLES OF RAD RADIUS AND CENTERED AT (1,1)
for l=1:5
radius=1/10^(l-1);
x = radius*cos(t) +1;
y = radius*sin(t) +1;
plot(x,y,':k','MarkerSize',100)
hold on
end
ezplot(g3,[-2,2.5,-2,2.5])
hold on
legend([p1 p2 p3 p4],'Feasible Region','f contours','minimum','sequence approaching x*');
title('Feasible Region, contour map and minimizer for Test 2');
hold off
But in this case, I do not know how to shade or add color to the feasible region.
3 comentarios
Respuestas (0)
Ver también
Categorías
Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!