# How can we fill a region defined by a implicit function?

28 views (last 30 days)
Maxim Bogdan on 17 Apr 2021 at 18:58
Commented: Star Strider on 17 Apr 2021 at 19:59
I use fimplicit(f, -10,10,-10,10) to plot the curve where . How can I color the region in which from the rectangle ?
I know a solution which is not that precise:
f=@(x,y) sin(x)*sin(y)-0.5;
x=linspace(a1,b1,100);
y=linspace(a2,b2,100);
[X,Y]=meshgrid(x,y);
condition=f(X,Y)>=0;
output=zeros(Nx,Ny);
output(~(condition))=1;
imshow(output, 'xdata', x, 'ydata', y);
axis on;
I don't know why the y-axis is reversed in that situation,and it appears smaller or greater depending on the length of x and y. Moreover I don't know how to use other colors than black and white (see here https://www.mathworks.com/matlabcentral/answers/297554-how-can-i-plot-the-region-for-two-inequalities). Anyway, is there a solution which maybe use the points we get from fimplicit?
fp=fimplicit(f,-10,10,-10,10);
Points=[fp.Xdata;fp.Ydata];
Maybe using patch or fill commands...? It works fine with patch if I have a connected curve, but this is not the case.
In Wolfram Alpha I just write f(x,y)>0 and the region is ploted. I wonder if there is such a code for Matlab too.
##### 2 CommentsShowHide 1 older comment
Star Strider on 17 Apr 2021 at 19:59
As always, my pleasure!

Star Strider on 17 Apr 2021 at 19:35
Edited: Star Strider on 17 Apr 2021 at 19:43
I am not certain what you want.
Try this:
f=@(x,y) sin(x).*sin(y)-0.5;
figure
fp1=fimplicit(f,[-10,10,-10,10]);
hold on
fp2=fcontour(f,[0,10,0,10]);
fp2.LevelList = [0 0];
fp2.Fill = 'on';
colormap([1 1 1; 0 1 0])
hold off
.
EDIT — (17 Apr 2021 at 19:43)
Another option:
f=@(x,y) sin(x).*sin(y)-0.5;
figure
fp1=fimplicit(f,[-10,10,-10,10]);
hold on
fp2=fcontour(f,[0,10,0,10]);
fp2.LevelList = linspace(0, 0.5, 25);
hold off
.