What you see as red and blue lines are the contours where the real- and imaginary-part of the complex expression is zero. For this, you can use ContourPlot
. You have to make explicit that z
is a complex variable that is x+I*y
:
expr = z^3 - z^2 - z - 1;
expr1 = ReIm[expr /. {z -> x + I y}];
After that, you can tell to plot the zero contour like this (MaxRecursion
is only for the beauty):
cp = ContourPlot[expr1, {x, -3, 3}, {y, -3, 3}, Contours -> {0}, MaxRecursion -> 4]
When you know that these lines are the zero lines, you instantly see that the crossings are the points where both are zero. This means you are searching the roots of your complex function.
roots = N@ReIm[z /. {ToRules@Reduce[expr == 0, z]}];
Show[cp, Graphics[{PointSize[0.03], Point[roots]}]]
Btw, if you feel the roots
lines is to complicated as a beginner, just rip it apart. You need the roots of your complex function and your expression is easy enough that you can do this analytically using Reduce
:
Reduce[expr == 0, z]
(* z == Root[-1 - #1 - #1^2 + #1^3 &, 1] ||
z == Root[-1 - #1 - #1^2 + #1^3 &, 2] ||
z == Root[-1 - #1 - #1^2 + #1^3 &, 3] *)
Mathematica gives you Root
expressions which basically means "the result is the root of this polynomial and I can give you the numbers if you like, but this representation is more clear and I'll keep it as long as you don't tell me otherwise".
Furthermore, you see that Reduce
gives a logical expression: solution 1 or solution 2 or solution 3. ToRules
will convert this into replacement rules and we can use z /.
to access it. Since the solutions are points in the complex plane I'm using ReIm
to get their real- and imaginary-part and finally N
to convert it to numbers.
Edit
As Bob mentioned in the comments, it maybe wasn't the best move to directly jump to Reduce
(whose difference to Solve
is not obvious to newcomers). You will get a better representation of your roots directly when you use Solve
:
Solve[expr == 0, z]
(* {
{z ->
1/3 (1 + (19 - 3 Sqrt[33])^(1/3) + (19 + 3 Sqrt[33])^(1/3))},
{z ->
1/3 - 1/6 (1 + I Sqrt[3]) (19 - 3 Sqrt[33])^(1/3) -
1/6 (1 - I Sqrt[3]) (19 + 3 Sqrt[33])^(1/3)},
{z ->
1/3 - 1/6 (1 - I Sqrt[3]) (19 - 3 Sqrt[33])^(1/3) -
1/6 (1 + I Sqrt[3]) (19 + 3 Sqrt[33])^(1/3)}
} *)
ReIm
): mathematica.stackexchange.com/questions/3458/… $\endgroup$