2
$\begingroup$

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.

$\endgroup$
4

1 Answer 1

1
$\begingroup$

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

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

Then evaluate your function

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)');

Contour plot

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.