Alex Dowad Computes
Explorations in the world of code

Visualizing the Complex Sine and Cosine

Mathematically inclined readers probably know the (real) sine and cosine functions like old friends; but are you just as intimate with the complex sine and cosine? This article will take you on a tour of their key properties, using interactive visualizations. (If you need a refresher on how complex numbers work, you could try this article from BetterExplained first.)

Before we start, what are the “complex sine and cosine” functions? One definition uses the power series for the real sine and cosine:

Take the same power series, and allow the value of x to be a complex number. That’s it! Or equivalently, you could take the exponential definition of the sine and cosine, and likewise, allow the input parameter x to take complex values.

So what do we get by letting x be complex? Does anything interesting happen? Do these new, generalized versions of the sine and cosine behave like the “normal” versions? Or do the familiar properties of sin and cos totally break down? Will graphing complex sin and cos result in some pretty pictures?[1]

We will start by listing the most important properties of the real sine and cosine, then go through the list one by one and see what happens to each property when we move into the complex domain. Here is my list:


sin(x) and cos(x)...

  1. ...are periodic, with period 2π.
  2. ...have bounded output values (from -1 up to 1).
  3. ...satisfy the Pythagorean Identity sin2(x)+cos2(x)=1 (for all x)
  4. ...are respectively odd and even (sin is odd, cos is even)
  5. ...are identical when cos is shifted forward (or sin shifted back) by π/2.
  6. ...are closed under differentiation (dxdsin(x)=cos(x), dxdcos(x)=sin(x))

So what about sin(z) and cos(z)?


1. Are they periodic, with period 2π?

Here are 3D plots of the real and imaginary parts of the complex sine. Rotate the view and look at them from different angles.

Drag to rotate, roll mouse wheel (or pinch) to zoom, Ctrl+drag to pan.

What do you conclude? Does it look periodic to you? (Click or tap to reveal the answer.)

2. Do their values range from -1 up to 1?

This one is obvious when you look at a graph. Here is a modular graph of the complex sine; the height of the graph represents the magnitude (Re(z)2+Im(z)2, also written as z) of the complex sine at that point. I’ve drawn a (white-colored) horizontal plane slicing the graph at z=1.

Again, drag to rotate, roll mouse wheel (or pinch) to zoom, Ctrl+drag to pan. Try peeking under the white plane at z=1 to see the familiar shape of the real sine function.

What do you conclude?

3. Does the Pythagorean Identity still work?

For real numbers, the Pythagorean Identity sin2(x)+cos2(x)=1 tells us that the sine and cosine of an angle can be thought of as the side lengths of a right triangle with unit hypotenuse. Like this:

Drag the arrow around the circle. The length of the red line is the sine, the length of the blue line is the cosine. Note that together with the arrow, they form a right triangle.

Using the interactive graph below, you can try to determine empirically if this is still true for the complex sine and cosine. Use your mouse (or finger on a mobile device) to drag the black point z all over the complex plane, and see what happens to sin(z), cos(z), sin2(z), cos2(z), and sin2(z)+cos2(z).

What do you conclude? Does it seem that sin2(z)+cos2(z)=1 holds?

4. Is cos(z) even, and sin(z) odd?

First, we need to think about what “even” and “odd” means in this context. For a real function, “even” means that the function is unchanged by reflecting across the y-axis, and “odd” means the function is negated by reflecting across the y-axis:

sin(x) is odd
cos(x) is even
Click (or tap) to flip the functions over like a couple of pancakes

For a complex function, the analogous operation is to reflect each point in the input space across the origin; instead of , we take .

If the complex sine is odd, meaning that , we should be able to take a vertical slice of its graph in any direction (though the slice must go through the origin), and just like the above graph of the real sine, the path it traces out on the left and right sides of the origin should be mirrored and “upside down” relative to each other.

To check this property empirically, let’s actually take some slices and see how they look! The 3D graph below plots the real part of the complex sine; move the slider to rotate the graph and take a slice at a different angle.

What do you conclude?

5. Are they identical after a π/2 phase shift?

Here is an overlay of the magnitudes of the complex sine and cosine; move the slider to shift the cosine along the real axis, and try to see at what shift (if any) the graphs coincide exactly. To make things easier to see, I’ll only graph on one side of the real axis. Since the magnitudes of the two functions are symmetrical across the real axis, nothing is lost by only showing one side.

And the same for the angles of the complex sine and cosine:

What do you conclude?

6. Do their derivatives still work in the same way?

Algebraically, it’s pretty obvious that we still have dzdsin(z)=cos(z), dzdcos(z)=sin(z). Just look at the power series definitions (or the exponential definitions) of the two functions. Since the rules for differentiating polynomials and exponentials are the same for real and complex variables, the result follows easily from either set of definitions.

However, I still want you to see this point visually. But what does the graph of a derivative-antiderivative pair look like? Below you can see a few examples of real functions and their derivatives. Click on the pink buttons one by one to highlight some basic features of derivative-antiderivative graphs:


The same visual features apply (roughly) to the magnitude of a complex derivative. A visualization will follow soon, but to appreciate it, you need to know a bit more about complex derivatives.

Real derivatives tell you the best linear approximation to a real function near a point. In symbols: f(x+Δx)f(x)+f(x)Δx. The same relationship applies to complex derivatives, but now f(z) and Δz are both complex. f(z) is a complex number which multiplies small deviations Δz from the input point z, giving a linear approximation to f(z+Δz).

But remember, complex multiplication includes both scaling and rotation. So unlike a real derivative, which just scales small deviations from a given input point, a complex derivative can both scale and rotate small deviations from an input point to approximate the corresponding output point.

Here is a little demonstration to build your intuition for how complex derivatives work. The black point z, below, represents an input to a complex function. Imagine that our view is zoomed in extremely close, so we are looking at just a tiny piece of the complex plane. The red point is the output of the same function. (For this demonstration, we don’t care what the function actually is; we are just interested in how its value changes for small changes of the input parameter.) Use your mouse cursor (or finger) to move the vector Δz around and watch where f(z+Δz) goes.

First, let’s say that (pure real), at least at this particular point z:

Now imagine our input point z has moved to some other place on the complex plane. Let’s say that here, (pure imaginary):

Finally, see what would happen if z moved to another location on the complex plane where is neither pure real nor pure imaginary:

After playing with those demonstrations, can you summarize how the magnitude and angle of a complex derivative control how the value of a complex function changes?

So then, let’s look at the complex sine and cosine again and see if we can identify visual features analogous to those highlighted in the above real derivative graphs. Move the input point z around the below grid, and the corresponding point on the sine and cosine plots will be highlighted. Try points where the magnitude of the cosine is large, those where it’s small, and those where it’s zero. Also, try points where the magnitude of the sine is large, small, or zero:

|sin(z)|
arg(sin(z))
|cos(z)|
arg(cos(z))

Can you see that both the magnitude and angle of the sine change fastest around points where the magnitude of the cosine is large? And likewise, the magnitude and angle of the cosine change fastest around points where the magnitude of the sine is large?

Digression: Most Complex Functions Don’t Have a Derivative

If you have studied basic calculus, you may know several reasons why a real function might not have a derivative (at least at certain points):

A complex function can fail to have a derivative for the same reasons, but there is another big reason why many, many complex functions do not have a derivative. Think about this: As was shown by the above interactive demonstration of how a complex derivative works, a complex derivative tells you how to scale and/or rotate small deviations from an input point to get the corresponding deviation from its output point. (In symbols: f(z+Δz)f(z)+f(z)Δz.) The demonstration showed that the rate of scaling and/or rotation caused by f(z) does not depend on the direction of Δz; that’s how complex multiplication works!

Example: if , then Δz will always be rotated by 90 degrees.

But now think about this: there are many, many functions (i.e. ways to map input points to output points) where f(z+Δz) depends very much on the direction of Δz. Here’s a simple example:

is z, is .
Drag the input point z around and observe how the output changes.

Try moving z around, and it will quickly become obvious that the direction which moves is not simply a rotated and/or scaled version of Δz; while z can move in any direction at all, only moves to the left or right, along the real axis. Since neither the angle between Δz and , nor the ratio of their magnitudes, is constant for a given position of z, the relationship between Δz and cannot be expressed as a simple complex multiplication by some number f(z)... but that’s precisely what a “complex derivative” means! And there we have it: does not have a derivative.

If you ever hear about “analytic functions”, that simply means “functions which have a complex derivative”. Like sin(z) and cos(z)!

Outro

I wanted to show that other trigonometric identities for the sine and cosine still work in the complex case, but couldn’t come up with good visualizations. In particular, I found it very hard to “see” in the graphs of the complex sine and cosine. Can you see it? If so, please share!

In any case, many trig identities follow directly from the exponential definitions of sine and cosine. Since exponentials have the same basic properties regardless of whether the parameter is real or complex, such trig identities naturally work either way.

One last little fact: If you slice the graph of sin(z) straight along the imaginary axis (going through the origin), you get the graph of sinh(x), the hyperbolic sine. It’s the same for cos(z); along the imaginary axis, it gives the graph of the hyperbolic cosine. If this intrigues you, have another look at the 3D graphs above and see if you can pick out the contours of the hyperbolic trig functions.

[1] Answers: “A lot”, “Yes”, “For the most part”, “Not really”, and “You can be the judge of that”.

This post left you burning to speak your mind? Reach out and e-mail the author! Selected replies will be published here.