Python ligistische Gleichung


import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib.animation import HTMLWriter

# Parameter
r_values = np.linspace(0.01, 4.0, 150)
n_iter = 200
x0 = 0.1

fig, ax = plt.subplots(figsize=(8, 5))
ax.set_xlim(0, n_iter)
ax.set_ylim(0, 1)
line, = ax.plot([], [], lw=2)
title = ax.set_title("")

def update(frame):
    r = r_values[frame]
    x = np.zeros(n_iter)
    x[0] = x0
    for i in range(1, n_iter):
        x[i] = r * x[i-1] * (1 - x[i-1])
    line.set_data(range(n_iter), x)
    title.set_text(f"Logistische Gleichung: r = {r:.3f}")
    return line, title

ani = animation.FuncAnimation(fig, update, frames=len(r_values), interval=100, blit=False)

# Speichern als HTML
ani.save("logistische_chaos_animation.html", writer=HTMLWriter())
print("Animation gespeichert als logistische_chaos_animation.html")