Line art

A new video from 3Blue1Brown is about visualizing derivatives as stretching and shrinking factors. Along the way they consider the function f(x) = 1 + 1/x.

Iterations of f converge on the golden ratio, no matter where you start (with one exception). The video creates a graph where they connect values of x on one line to values of f(x) on another line. Curiously, there’s an oval that emerges where no lines cross.

Here’s a little Python I wrote to play with this:

    import matplotlib.pyplot as plt
    from numpy import linspace

    N = 70
    x = linspace(-3, 3, N)
    y = 1 + 1/x

    for i in range(N):
        plt.plot([x[i], y[i]], [0, 1])
    plt.xlim(-5, 5)

And here’s the output:

In the plot above I just used matplotlib’s default color sequence for each line. In the plot below, I used fewer lines (N = 50) and specified the color for each line. Also, I made a couple changes to the plot command, specifying the color for each line and putting the x line above the y line.

        plt.plot([x[i], y[i]], [0, 1], c="#243f6a")

If you play around with the Python code, you probably want to keep N even. This prevents the x array from containing zero.

Update: Here’s a variation that extends the lines connecting (x, 0) and (y, 1). And I make a few other changes while I’m at it.

    N = 200
    x = linspace(-10, 10, N)
    y = 1 + 1/x
    z = 2*y-x

    for i in range(N):
        plt.plot([x[i], z[i]], [0, 2], c="#243f6a")
    plt.xlim(-10, 10)

5 thoughts on “Line art

  1. Steps for finding the equation for the ellipse:
    – implicit equation for a line: a*x+b*y+c=0
    – find a, b, c such that the line goes through (t, 0) and (f(t), 1)
    – the solution a=-t, b=-t^2+t+1, c=t^2, gives
    F(t, x, y) = -t+(-t^2+t+1)*x+t^2*c = 0
    – the envelope equation (see Wikipedia page) is given by eliminating t from diff(F(t, x, y), t) = 0 and F(t, x, y) = 0

    These steps also work for the more general case f(x) = c1 + c2/(x-c3) in John’s demo. You still get an ellipse, but for c3 not zero, things are a bit more complicated.

  2. This is interesting. I wonder if these envelopes of dead space exist for other functions and if they give some insight into how the function behaves

  3. Actually, all the cases in John’s demo (different values of c1, c2 and c3) are equivalent up to affine transformation of (x, y). This means that it is enough to consider the case f(x)=1/x. Since ellipses stay ellipses under affine transformations, it follows that the envelope is always an ellipse.

Leave a Reply

Your email address will not be published.