Search code examples
matlabmatlab-figureimplicit-conversioncomplex-numbers

Filling a region in the complex plane in Matlab


So I have plotted the the function defined implicitly by fimplicit in Matlab. I want to fill the region inside. How to do that?

f1=@(x,y) (1+x+x.^2-y.^2).^2+(y+2.*x.*y).^2-1;

fimplicit(f1)
hold on
axis([-1.5 0.5 -1.5 1.5])
xlabel('Re(h\lambda)')
ylabel('Im(h\lambda)')
hold off

enter image description here


Solution

  • Just use fill with inputs given by the XData and YData properties of the ImplicitFunctionLine object produced by fimplicit:

    f1 = @(x,y) (1+x+x.^2-y.^2).^2+(y+2.*x.*y).^2-1;
    h = fimplicit(f1, 'linewidth', 1);
    hold on
    axis([-1.5 0.5 -1.5 1.5])
    xlabel('Re(h\lambda)')
    ylabel('Im(h\lambda)')
    fill(h.XData, h.YData, 'b', 'FaceAlpha', .1)
    

    enter image description here