fork download
  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3.  
  4. # 한글 폰트 및 마이너스 기호 깨짐 방지 설정
  5. plt.rcParams['font.family'] = 'sans-serif'
  6. plt.rcParams['axes.unicode_minus'] = False
  7.  
  8. # 1. 시간 범위 설정 (예: 0일부터 8일까지)
  9. t = np.linspace(0, 8, 400)
  10.  
  11. # 2. 식물의 생장량 함수 f(t) 정의 (3차 함수 모델)
  12. # f(t) = -t^3 + 9t^2 + 12t (단위: cm)
  13. # 초기에는 천천히 자라다가 속도가 붙은 뒤 완만해지는 S자 곡선의 형태를 일부 모사합니다.
  14. f_t = -(t**3) + 9 * (t**2) + 12 * t
  15.  
  16. # 3. 도함수 f'(t) 정의 (순간 성장 속도, 2차 함수)
  17. # f'(t) = -3t^2 + 18t + 12
  18. f_prime_t = -3 * (t**2) + 18 * t + 12
  19.  
  20. # 4. 성장이 가장 빠른 시점(도함수의 꼭짓점, 즉 2차함수 대칭축 공식 t = -b / 2a) 계산
  21. # -3t^2 + 18t + 12 에서 a = -3, b = 18 이므로 t = -18 / (2 * -3) = 3
  22. t_max_growth = 3.0
  23. max_growth_rate = -3 * (t_max_growth**2) + 18 * t_max_growth + 12
  24. max_height = -(t_max_growth**3) + 9 * (t_max_growth**2) + 12 * t_max_growth
  25.  
  26. # 결과 출력
  27. print(
  28. f'[수학적 모델링 분석 결과]\n'
  29. f'- 식물이 가장 폭발적으로 자라는 시점: t = {t_max_growth}일\n'
  30. f'- 이때의 최대 순간 성장 속도: {max_growth_rate} cm/일\n'
  31. f'- 이때의 식물 높이: {max_height} cm'
  32. )
  33.  
  34. # 5. 그래프 시각화 (위: 원함수 / 아래: 도함수)
  35. fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(10, 8), sharex=True)
  36.  
  37. # (1) 원함수 그래프: 시간(t)에 따른 식물의 높이 f(t)
  38. ax1.plot(
  39. t, f_t, label='Plant Height f(t)', color='forestgreen', linewidth=2.5
  40. )
  41. ax1.axvline(
  42. x=t_max_growth,
  43. color='orange',
  44. linestyle='--',
  45. label=f'Max Growth Time (t={t_max_growth})',
  46. )
  47. ax1.set_ylabel('Plant Height (cm)', fontsize=12)
  48. ax1.set_title(
  49. "Math II Application: Plant Growth & Derivative Model", fontsize=14
  50. )
  51. ax1.grid(True, linestyle=':', alpha=0.7)
  52. ax1.legend(loc='upper left')
  53.  
  54. # (2) 도함수 그래프: 시간(t)에 따른 순간 성장 속도 f'(t)
  55. ax2.plot(
  56. t,
  57. f_prime_t,
  58. label="Growth Rate f'(t)",
  59. color='dodgerblue',
  60. linewidth=2.5,
  61. )
  62. ax2.scatter(
  63. [t_max_growth],
  64. [max_growth_rate],
  65. color='red',
  66. zorder=5,
  67. s=80,
  68. label=f'Max Growth Rate ({max_growth_rate} cm/day)',
  69. )
  70. ax2.axvline(x=t_max_growth, color='orange', linestyle='--')
  71. ax2.set_xlabel('Time t (days)', fontsize=12)
  72. ax2.set_ylabel('Growth Rate (cm/day)', fontsize=12)
  73. ax2.grid(True, linestyle=':', alpha=0.7)
  74. ax2.legend(loc='upper right')
  75.  
  76. plt.tight_layout()
  77. plt.show()
  78.  
Success #stdin #stdout 0.94s 54696KB
stdin
Standard input is empty
stdout
[수학적 모델링 분석 결과]
- 식물이 가장 폭발적으로 자라는 시점: t = 3.0일
- 이때의 최대 순간 성장 속도: 39.0 cm/일
- 이때의 식물 높이: 90.0 cm