fork download
  1. import matplotlib.pyplot as plt
  2.  
  3. # 定义计算乒乓球弹起高度的函数
  4. def calculate_bounce_height(diameter, release_height):
  5. return release_height * (diameter / 10) ** 0.5
  6.  
  7. # 定义直径和释放高度
  8. diameters = [10, 15, 20, 25]
  9. heights = [50, 100, 150, 200]
  10.  
  11. # 绘制曲线图
  12. plt.figure(figsize=(10, 6))
  13. for diameter in diameters:
  14. bounce_heights = [calculate_bounce_height(diameter, height) for height in heights]
  15. plt.plot(heights, bounce_heights, label=f'Diameter {diameter} cm')
  16.  
  17. plt.xlabel('Release Height (cm)')
  18. plt.ylabel('Bounce Height of Ping Pong Ball (cm)')
  19. plt.title('Ping Pong Ball Bounce Height vs. Release Height for Different Container Diameters')
  20. plt.legend()
  21. plt.grid()
  22. plt.show()
Success #stdin #stdout 0.04s 25728KB
stdin
Standard input is empty
stdout
import matplotlib.pyplot as plt

# 定义计算乒乓球弹起高度的函数
def calculate_bounce_height(diameter, release_height):
    return release_height * (diameter / 10) ** 0.5

# 定义直径和释放高度
diameters = [10, 15, 20, 25]
heights = [50, 100, 150, 200]

# 绘制曲线图
plt.figure(figsize=(10, 6))
for diameter in diameters:
    bounce_heights = [calculate_bounce_height(diameter, height) for height in heights]
    plt.plot(heights, bounce_heights, label=f'Diameter {diameter} cm')

plt.xlabel('Release Height (cm)')
plt.ylabel('Bounce Height of Ping Pong Ball (cm)')
plt.title('Ping Pong Ball Bounce Height vs. Release Height for Different Container Diameters')
plt.legend()
plt.grid()
plt.show()