# Contour plot of a scalar function over the complex domain in MATLAB

I'm trying to make a 2D contour plot of a function with a complex input and a real output, namely: $f(z=x+iy)= |z^2-3z|$, on MATLAB. I want to make a contour plot of f, such that the axes are $(x,y)$, i.e. $(\Re(z),\Im(z))$.

How is this done in MATLAB? The problem I'm having is the fact the input is complex.

You need to define a mesh over which your function will be evaluated

[mfRe, mfIm] = ndgrid(-1, 1, 100);


fh = @(z)abs(z.^2 - 3 .* z);
mfF = fh(complex(mfRe, mfIm));


Now make the contour plot and beautify

contour(mfRe, mfIm, mfF);
axis equal;
xlabel('Re(z)');
ylabel('Im(z)');