import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

# 데이터 생성
angles = np.arange(0, 361, 10)
# np.full_like : 주어진 배열과 동일한 크기와 데이터 타입을 가지면서, 모든 요소를 특정 값으로 채운 새로운 배열을 생성
boom_lengths = np.full_like(angles, 10)  # 10m
loads = np.full_like(angles, 5000)  # 5000kg

# DataFrame 생성
data = pd.DataFrame({
    'Angle (deg)': angles,
    'Boom Length (m)': boom_lengths,
    'Load (kg)': loads
})

# 계산 (data에 계산결과 추가)
data['Angle (rad)'] = np.deg2rad(data['Angle (deg)'])
data['Moment (Nm)'] = data['Load (kg)'] * data['Boom Length (m)'] * np.sin(data['Angle (rad)'])

# 출력
print(data)

# 시각화
plt.plot(data['Angle (deg)'], data['Moment (Nm)'], marker='o', label='Moment')
plt.xlabel('Angle (deg)')
plt.ylabel('Moment (Nm)')
plt.title('Crane Boom Moment vs Angle')
plt.legend()
plt.grid(True)
plt.show()

Retrieved from http://memorecycle.com/w/Python/Numpy
last modified 2025-01-12 16:01:22