import numpy as np
import matplotlib.pyplot as plt
import os, cv2, glob
sigma, b, r = 10, 8./3., 470./19.
npts, dt = 4000, 0.01
x, y, z, xp = np.zeros(npts), np.zeros(npts), np.zeros(npts), np.zeros(npts)
x[0], y[0], z[0] = 0.0, 2.0, 2.0
if not os.path.exists('./fig'): os.makedirs('./fig')
sample_freq, k = 10, 0
for i in range(npts-1):
dxdt, dydt, dzdt = -sigma * x[i] + sigma * y[i], -x[i]*z[i] + r*x[i] - y[i], x[i]*y[i] - b*z[i]
x[i+1], y[i+1], z[i+1], xp[i] = x[i] + dt * dxdt, y[i] + dt * dydt, z[i] + dt * dzdt, dt * i
if i % sample_freq == 0:
k += 1
fig, axs = plt.subplots(2, 3, figsize=(10, 5))
axs[0, 0].plot(xp[:i], x[:i]), axs[0, 1].plot(xp[:i], y[:i]), axs[0, 2].plot(xp[:i], z[:i])
axs[1, 0].plot(x[:i], y[:i]), axs[1, 1].plot(y[:i], z[:i]), axs[1, 2].plot(x[:i], z[:i])
for ax in axs.flat: ax.plot(xp[i-2:i], x[i-2:i], 'o')
plt.tight_layout(), plt.savefig(f"./fig/{k:05}.png"), plt.close(fig)
jpg_files = sorted(glob.glob('./fig/*.png'))
height, width, _ = cv2.imread(jpg_files[0]).shape
out = cv2.VideoWriter("20240806.mp4", cv2.VideoWriter_fourcc(*'mp4v'), 10.0, (width, height))
for jpg in jpg_files: out.write(cv2.imread(jpg))
out.release(), cv2.destroyAllWindows(), print("Video created: 20240806.mp4")
Негізгі бет Butterfly Effect, Lorenz Model, Compete Python Code. Have fun and Enjoy the nonlinear process
Пікірлер: 1