fork download
  1.  
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4.  
  5. # 1. 시간 설정 (0~4일)
  6. t = np.linspace(0, 4, 401)
  7.  
  8. # 2. 가상의 식물 생장량 함수
  9. # N(t) = 10 + ((t-2)^3 + 8)/3 + t
  10. def growth(t):
  11. return 10 + ((t - 2)**3 + 8) / 3 + t
  12.  
  13. # 3. 순간 생장 속도 함수: N'(t)
  14. def growth_rate(t):
  15. return (t - 2)**2 + 1
  16.  
  17. # 4. 비교할 두 시점
  18. t1 = 1
  19. t2 = 3
  20.  
  21. N1 = growth(t1)
  22. N2 = growth(t2)
  23.  
  24. R1 = growth_rate(t1)
  25. R2 = growth_rate(t2)
  26.  
  27. # 5. 결과 출력
  28. print("===== 생장 상태 비교 =====")
  29. print(f"{t1}일째 생장량: {N1:.2f}")
  30. print(f"{t2}일째 생장량: {N2:.2f}")
  31. print()
  32. print(f"{t1}일째 순간 생장 속도: {R1:.2f}")
  33. print(f"{t2}일째 순간 생장 속도: {R2:.2f}")
  34. print()
  35. print(f"생장량 차이: {abs(N2 - N1):.2f}")
  36. print(f"생장 속도 차이: {abs(R2 - R1):.2f}")
  37.  
  38. # 6. 그래프 그리기
  39. fig, axes = plt.subplots(1, 2, figsize=(12, 4.5))
  40.  
  41. # 생장량 그래프
  42. axes[0].plot(t, growth(t), label="Growth amount N(t)")
  43. axes[0].scatter([t1, t2], [N1, N2], color="red", zorder=3)
  44. axes[0].annotate(f"t=1, N={N1:.2f}", (t1, N1),
  45. xytext=(5, 10), textcoords="offset points")
  46. axes[0].annotate(f"t=3, N={N2:.2f}", (t2, N2),
  47. xytext=(5, 10), textcoords="offset points")
  48. axes[0].set_title("Plant Growth Amount")
  49. axes[0].set_xlabel("Time (days)")
  50. axes[0].set_ylabel("Growth amount (arbitrary units)")
  51. axes[0].grid(True)
  52. axes[0].legend()
  53.  
  54. # 순간 생장 속도 그래프
  55. axes[1].plot(t, growth_rate(t), label="Growth rate N'(t)")
  56. axes[1].scatter([t1, t2], [R1, R2], color="red", zorder=3)
  57. axes[1].annotate(f"t=1, rate={R1:.1f}", (t1, R1),
  58. xytext=(5, 10), textcoords="offset points")
  59. axes[1].annotate(f"t=3, rate={R2:.1f}", (t2, R2),
  60. xytext=(5, 10), textcoords="offset points")
  61. axes[1].set_title("Instantaneous Growth Rate")
  62. axes[1].set_xlabel("Time (days)")
  63. axes[1].set_ylabel("Growth rate (units/day)")
  64. axes[1].grid(True)
  65. axes[1].legend()
  66.  
  67. plt.tight_layout()
  68. plt.show()
  69.  
Success #stdin #stdout 1.04s 53492KB
stdin
Standard input is empty
stdout
===== 생장 상태 비교 =====
1일째 생장량: 13.33
3일째 생장량: 16.00

1일째 순간 생장 속도: 2.00
3일째 순간 생장 속도: 2.00

생장량 차이: 2.67
생장 속도 차이: 0.00