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)