import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import tkinter as tk
# 로렌츠 방정식 정의
def lorenz(X, t, sigma, beta, rho):
x, y, z = X
dx_dt = sigma * (y - x)
dy_dt = x * (rho - z) - y
dz_dt = x * y - beta * z
return [dx_dt, dy_dt, dz_dt]
# 그래프 그리기 함수
def plot_lorenz(sigma, beta, rho, x0, y0, z0):
t = np.linspace(0, 50, 10000)
initial_state = [x0, y0, z0]
solution = odeint(lorenz, initial_state, t, args=(sigma, beta, rho))
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
ax.plot(solution[:, 0], solution[:, 1], solution[:, 2], lw=0.5)
ax.set_title("Lorenz Attractor")
ax.set_xlabel("X Axis")
ax.set_ylabel("Y Axis")
ax.set_zlabel("Z Axis")
canvas = FigureCanvasTkAgg(fig, master=window)
canvas.draw()
canvas.get_tk_widget().pack()
# 버튼 클릭 이벤트
def on_submit():
try:
sigma = float(entry_sigma.get())
beta = float(entry_beta.get())
rho = float(entry_rho.get())
x0 = float(entry_x0.get())
y0 = float(entry_y0.get())
z0 = float(entry_z0.get())
plot_lorenz(sigma, beta, rho, x0, y0, z0)
except ValueError:
tk.messagebox.showerror("입력 오류", "올바른 숫자를 입력해주세요.")
# GUI 설정
window = tk.Tk()
window.title("Lorenz Equations Solver")
tk.Label(window, text="Sigma (σ):").pack()
entry_sigma = tk.Entry(window)
entry_sigma.pack()
tk.Label(window, text="Beta (β):").pack()
entry_beta = tk.Entry(window)
entry_beta.pack()
tk.Label(window, text="Rho (ρ):").pack()
entry_rho = tk.Entry(window)
entry_rho.pack()
tk.Label(window, text="Initial x:").pack()
entry_x0 = tk.Entry(window)
entry_x0.pack()
tk.Label(window, text="Initial y:").pack()
entry_y0 = tk.Entry(window)
entry_y0.pack()
tk.Label(window, text="Initial z:").pack()
entry_z0 = tk.Entry(window)
entry_z0.pack()
submit_button = tk.Button(window, text="Plot Lorenz Attractor", command=on_submit)
submit_button.pack()
window.mainloop()
https://www.tistory.com/event/write-challenge-2024
'정보통신기술(ICT)' 카테고리의 다른 글
반데르발스 헤테르구조(Vanderwaals Heterostructures) (3) | 2024.11.06 |
---|---|
양자역학: 터널링 효과(Quantum Tunneling Effect) (4) | 2024.11.05 |
양자역학: 입자상자 문제(Particle in a Box) (3) | 2024.11.01 |
열역학: 볼츠만 분포(Boltzmann Distribution) (0) | 2024.10.31 |
로지스틱 함수 (0) | 2024.10.30 |