Filling area common to two inequalities?

7 views (last 30 days)
SAJAN Phutela
SAJAN Phutela on 27 Jan 2023
Commented: SAJAN Phutela on 27 Jan 2023
I am having two inequalities (one is explicit and another in implicit) and I want to fill the area common to these. I have drawn the corresponding equations in matlab but do not know how can I fill the common area. I am also uploading the image in which coloured their common area with help of paint. My code is:
clc;
clear all;
E11=0.041057; E12=-0.117734; E21=0.029952; E22=-0.042564;
A=[1 -E22/E11];
D0=E11*E22-E12*E21
x = linspace(-1, 7); % Row Vector
y1=max(A)*x ;
F=@(x,y) E11.^2*y.^2+E22.^2*x.^2+(2*x.*y.*E11.*E22-4.*x.*y.*D0);
plot(x, y1,'--b','linewidth',1.3)
hold on
fimplicit(F,[0 7 0 20],'--r','linewidth',1.3)
xlim([0,7])
ylim([0,20])
I want to fill the area in which y1>0 and F>0 which is filled with orange color in below image.

Answers (1)

KSSV
KSSV on 27 Jan 2023
clc;
clear all;
E11=0.041057;
E12=-0.117734;
E21=0.029952;
E22=-0.042564;
A=[1 -E22/E11];
D0=E11*E22-E12*E21 ;
x1 = linspace(-1, 7); % Row Vector
y1=max(A)*x1 ;
F=@(x,y) E11.^2*y.^2+E22.^2*x.^2+(2*x.*y.*E11.*E22-4.*x.*y.*D0);
[X,Y] = meshgrid(linspace(0,7),linspace(0,20)) ;
F = F(X,Y) ;
[c,h] = contour(X,Y,F,[0 0]) ;
c(:,1) =[] ;
x2 = c(1,:) ;
y2 = c(2,:) ;
plot(x1, y1,'--b','linewidth',1.3)
hold on
plot(x2,y2,'--r','linewidth',1.3)
xlim([0,7])
ylim([0,20])
Now you have the coordinates (x1,y1) and (x2,y2) in hand. You can pick the required coordinates you want and use polyarea
  2 Comments
SAJAN Phutela
SAJAN Phutela on 27 Jan 2023
Can u please tell how can I feel the area using polyarea? I have not used earlier, thanks please.
SAJAN Phutela
SAJAN Phutela on 27 Jan 2023
@KSSV thanx for you reply, I also did it but in a different manner, please have alook on it
clc;
clear all;
E11=0.041057;
E12=-0.117734;
E21=0.029952;
E22=-0.042564;
A=[1 -E22/E11];
D0=E11*E22-E12*E21 ;
xmax=5; ymax=20;
F1=@(x,y) E11.^2*y.^2+E22.^2*x.^2+(2*x.*y.*E11.*E22-4.*x.*y.*D0);
F2=@(x,y) y-max(A)*x;
Q1=linspace(0,xmax,500); Q2=linspace(0,ymax,500);
[X,Y] = meshgrid(Q1,Q2) ;
G1 = F1(X,Y) ; %Evaluate the value of functions at grid points
G2= F2(X,Y) ;
[row1,col1] =find(G1>0 & G2>0); % returns the indexing of grid points where conditions are satisfied
row2=col1; col2=row1; % returns the intices of in x and y
X1=Q1(row2); Y1=Q2(col2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
plot(X1,Y1,'.b','MarkerSize',5)
hold on
fimplicit(F1,[0 7 0 20],'-r','linewidth',1.5)
fimplicit(F2,[0 7 0 20],'-g','linewidth',1.5)
xlim([0,xmax])
ylim([0,ymax])

Sign in to comment.

Tags

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!