import tkinter as tk
import math
import matplotlib.pyplot as plt
import numpy as np
def logistic_function(L, k, x0, x):
return L / (1 + math.exp(-k * (x - x0)))
def plot_logistic(L, k, x0):
x_values = np.linspace(-10, 10, 200) # X 범위 설정
y_values = L / (1 + np.exp(-k * (x_values - x0))) # 로지스틱 함수 계산
plt.figure(figsize=(8, 6))
plt.plot(x_values, y_values, label=f"Logistic Function (L={L}, k={k}, x0={x0})")
plt.xlabel("x")
plt.ylabel("f(x)")
plt.title("Logistic Function Graph")
plt.legend()
plt.grid(True)
plt.show()
def calculate_and_plot_logistic():
try:
L = float(entry_L.get())
k = float(entry_k.get())
x0 = float(entry_x0.get())
x = float(entry_x.get())
# 결과값 계산 및 출력
result = logistic_function(L, k, x0, x)
label_result.config(text=f"Result: {result:.4f}")
# 그래프 그리기
plot_logistic(L, k, x0)
except ValueError:
label_result.config(text="Please enter valid numbers.")
# GUI 설정
root = tk.Tk()
root.title("Logistic Function Calculator and Plotter")
# 라벨과 입력 필드 설정
tk.Label(root, text="L (Maximum value)").grid(row=0, column=0)
entry_L = tk.Entry(root)
entry_L.grid(row=0, column=1)
tk.Label(root, text="k (Growth rate)").grid(row=1, column=0)
entry_k = tk.Entry(root)
entry_k.grid(row=1, column=1)
tk.Label(root, text="x0 (Midpoint)").grid(row=2, column=0)
entry_x0 = tk.Entry(root)
entry_x0.grid(row=2, column=1)
tk.Label(root, text="x (Input value)").grid(row=3, column=0)
entry_x = tk.Entry(root)
entry_x.grid(row=3, column=1)
# 결과 라벨 및 계산 버튼
label_result = tk.Label(root, text="Result: ")
label_result.grid(row=5, column=0, columnspan=2)
button_calculate = tk.Button(root, text="Calculate and Plot", command=calculate_and_plot_logistic)
button_calculate.grid(row=4, column=0, columnspan=2)
# GUI 실행
root.mainloop()
https://www.tistory.com/event/write-challenge-2024
'정보통신기술(ICT)' 카테고리의 다른 글
양자역학: 입자상자 문제(Particle in a Box) (3) | 2024.11.01 |
---|---|
열역학: 볼츠만 분포(Boltzmann Distribution) (0) | 2024.10.31 |
맵 타임랩스 소프트웨어(10.29.24) (0) | 2024.10.29 |
맵 타임랩스 소프트웨어 (0) | 2024.10.28 |
수리 물리학: 베셀 함수(Bessel Function) (0) | 2024.10.25 |