All problems
Lyapunov Exponent 1D Map
Problem
The Lyapunov exponent of the logistic map measures the average exponential separation of nearby orbits:
lambda = (1/n) * sum of ln|f'(x_k)| along the orbit.
Iterate x = r*x*(1-x) for n steps starting from x0, accumulating ln|r*(1 - 2x)| before each update, and return the average. A positive exponent signals chaos.
Hint
At r = 4 the theoretical Lyapunov exponent is ln(2), about 0.6931.
Test cases
case 1
in: [4,0.1,1000]
expected: 0.6934349555043721
case 2
in: [4,0.123456,500]
expected: 0.6939785071798493
case 3
in: [3.8,0.2,500]
expected: 0.41391435195894055
case 4
in: [4,0.3,2000]
expected: 0.6929468914389755
Starter codePython
def lyapunov_exponent(r, x0, n):
# Your code here
pass4 test cases · run your code against them in the editor