当前位置: 首页 > article >正文

【混沌系统】洛伦兹吸引子-Python动画

在这里插入图片描述

lorenz_attractor_animation

代码如下:

import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import solve_ivp
from matplotlib.animation import FuncAnimation

# Lorenz attractor parameters
sigma = 10.0
rho = 28.0
beta = 8.0 / 3.0


# Lorenz system differential equations
def lorenz(t, state):
    """
    Computes the derivatives of the Lorenz system equations.

    Args:
        t: Time variable (unused).
        state: Current state of the system (x, y, z).

    Returns:
        List of derivatives [dxdt, dydt, dzdt].
    """
    x, y, z = state
    dxdt = sigma * (y - x)
    dydt = x * (rho - z) - y
    dzdt = x * y - beta * z
    return [dxdt, dydt, dzdt]


# Time span and initial state
t_span = (0, 40)
initial_state = [1.0, 1.0, 1.0]
t_eval = np.linspace(*t_span, 6000)

# Solving the system
solution = solve_ivp(lorenz, t_span, initial_state, t_eval=t_eval)
x, y, z = solution.y

# Set up the figure and 3D axis
fig = plt.figure(figsize=(10, 7))
ax = fig.add_subplot(111, projection='3d')
ax.set_xlim((np.min(x), np.max(x)))
ax.set_ylim((np.min(y), np.max(y)))
ax.set_zlim((np.min(z), np.max(z)))
ax.set_title("Lorenz Attractor - Animation")
ax.set_xlabel("X-axis")
ax.set_ylabel("Y-axis")
ax.set_zlabel("Z-axis")

# Initialize the line object to be updated
line, = ax.plot([], [], [], lw=0.5, color='b')


# Update function for the animation
def update(num):
    """
    Updates the line object for the animation based on the current frame number.

    Args:
        num: Current frame number.

    Returns:
        Tuple containing the updated line object.
    """
    line.set_data(x[:num], y[:num])
    line.set_3d_properties(z[:num])
    return line,


# Create the animation
frames = 7000
ani = FuncAnimation(fig, update, frames=frames, blit=True, interval=2)

# Save the animation as an MP4 file
output_path = "E:/pycharm all files/绘图/lorenz_attractor_animation.mp4"  # Change this to an existing path on your computer
ani.save(output_path, writer="ffmpeg", dpi=100)

print(f"Animation saved to: {output_path}")



http://www.kler.cn/a/394059.html

相关文章:

  • 软件工程师简历(精选篇)
  • 软件测试:测试用例详解
  • Linux基础1
  • 06.VSCODE:备战大项目,CMake专项配置
  • docker:docker: Get https://registry-1.docker.io/v2/: net/http: request canceled
  • 应用于新能源汽车NCV4275CDT50RKG车规级LDO线性电压调节器芯片
  • vueRouter路由切换时实现页面子元素动画效果, 左右两侧滑入滑出效果
  • 数据分析编程:SQL,Python or SPL?
  • 机器学习—为什么我们需要激活函数
  • 分享 | 中望3D 2025发布会提及的工业数字化MBD是什么?
  • 本溪与深圳市新零售产业互联协会共商世界酒中国菜湾区农业发展
  • 力扣257:二叉树的所有路径
  • adb不识别设备(手机)的若干情形及解决方法
  • 研究生如何远控实验室电脑?远程办公功能使用教程
  • 论文学习_Efficient Algorithms for Personalized PageRank Computation: A Survey
  • 【案例】定性数据分析软件NVivo 在医疗保健领域的应用
  • A034-基于Spring Boot的供应商管理系统的设计与实现
  • Excel筛选的操作教程
  • ThreadLocal原理及其内存泄漏
  • AI云产品,缺运维技术指南
  • 区块链智能合约开发:全面解析与实践指南
  • 在使用ipc通信时 ,在渲染进程的Vue + TypeScript 开发过程,给window对象添加属性并赋值时,发生报错解决方法
  • docker打包nginx版wordpress
  • Spring Boot基础教学:开发工具和环境
  • swoole mysql连接池使用
  • 网络安全web基础_HTML基础(扫盲篇)