# T자 모양 단면의 도심<br>Centroid of a T shaped Section




```python
# 그래프, 수학 기능 추가
# Add graph and math features
import pylab as py
import numpy as np
import numpy.linalg as nl
# 기호 연산 기능 추가
# Add symbolic operation capability
import sympy as sy


```

참고문헌 : 예제 5.2, Pytel 외 저, 이주성 외 역, 재료역학, 2판, 한티미디어, 2013.<br>Ref: Example 5.2, Pytel, Kiusalaas, Sharma, Mechanics of Materials, 2nd Ed., Cengage Learning, 2013.



다음과 같은 T자 모양 단면의 도심을 구해 보자.<br>
Let's try to find the centroid of the following T shaped section.



윗 변의 폭 $w=150mm$<br>Width of the upper side $w=150mm$




```python
w_mm = 150


```

아랫변의 높이 $h=200mm$<br>Height of the lower side $h=200mm$




```python
h_mm = 200


```

두께 $t=20mm$<br>Thickness $t=20mm$




```python
t_mm = 20


```

## 도심의 정의<br>Definition of a Centroid



$$
C_y=\frac{\int yS_x(y) dy}{A}=\frac{\int yS_x(y) dy}{\int S_x(y) dy}
$$



ref : https://en.wikipedia.org/wiki/Centroid



여기서 $S_x(y)$는 다음과 같다. (T 단면의 아래 끝에서 $y=0$)<br>
Here, $S_x(y)$ is as follows. ($y=0$ at the lower end of T section)



$$
S_x(y) = 
\begin{cases}
t, & 0 \leq y < h \\
w, & h \leq y < h + t \\
0, & otherwise
\end{cases}
$$



Python 언어로는 다음과 같이 구현할 수 있다.<br>We can implement in python as follows.




```python
def sx(y_mm):
    if 0 <= y_mm < h_mm :
        result = t_mm
    elif h_mm <= y_mm < (h_mm + t_mm):
        result = w_mm
    else:
        result = 0

    return result


```

이 함수의 그래프를 그려 보자<br>Let's plot this.




```python
y_mm_array = py.arange(0, h_mm + t_mm + 0.5, 1)
sx_mm_array = py.array([sx(y_mm) for y_mm in y_mm_array])

py.plot(sx_mm_array * 0.5, y_mm_array)
py.plot(sx_mm_array * (-0.5), y_mm_array)

py.axis('equal')
py.grid(True)

py.xlabel('x(mm)')
py.xlabel('y(mm)')


```

## 정적분 계산<br>Numerical Integration



0차 적분 함수를 이용해 보자<br>Let's use 0'th order numerical integration function.




```python
def num_int_0(f, xi, xe, delta_x):
    x_array = py.arange(xi, xe+delta_x*0.1, delta_x)
    
    integration_result = 0.0
    
    for x_i in x_array:
        y_i = f(x_i)
        area_i = delta_x * y_i
        integration_result += area_i
    
    return integration_result


```

### 단면적<br>Area of the section




```python
A_mm2 = num_int_0(sx, 0, h_mm + t_mm, 1)


```


```python
A_mm2


```

확인해 보자.<br>Let's verify.




```python
h_mm * t_mm + w_mm * t_mm


```

아래와 같이 지정해 두면 T 자 단면적 결과가 맞는지 확인할 수 있다.<br>
We can designate as follows to assert T shape section area.




```python
assert 1e-6 > abs((h_mm * t_mm + w_mm * t_mm) - A_mm2)


```

### 도심<br>Centroid




```python
def ySx(y_mm):
    return y_mm * sx(y_mm)


```


```python
numerator_mm3 = num_int_0(ySx, 0, h_mm + t_mm, 1)


```


```python
cy_mm = numerator_mm3 / A_mm2


```


```python
cy_mm


```

역시 확인해 보자.<br>Again, let's verify.




```python
cy_exact_mm = ((h_mm * t_mm) * (h_mm * 0.5) + (w_mm * t_mm) * (h_mm + 0.5 * t_mm)) / (h_mm * t_mm + w_mm * t_mm)


```


```python
cy_exact_mm


```


```python
cy_mm - cy_exact_mm


```

어떻게 하면 위 오차를 줄일 수 있을 것인가?<br>How can we make the error above smaller?




```python
error = (cy_mm - cy_exact_mm)


```


```python
try : 
    assert (1e-6 > abs(error)), "Error too large"
except AssertionError as e:
    print(e)


```

## Final Bell<br>마지막 종




```python
# stackoverfow.com/a/24634221
import os
os.system("printf '\a'");


```


```python



```

c119f351e357d2430360195938c936de724f0a0e
ipynb
Jupyter Notebook
30_num_int/10_T_section_centroid.ipynb
cv2316eca19a/nmisp
731a01bc687f3380ddf370d45c3a286f754b45cb
BSD-3-Clause
30_num_int/10_T_section_centroid.ipynb
cv2316eca19a/nmisp
731a01bc687f3380ddf370d45c3a286f754b45cb
BSD-3-Clause
30_num_int/10_T_section_centroid.ipynb
cv2316eca19a/nmisp
731a01bc687f3380ddf370d45c3a286f754b45cb
BSD-3-Clause
Qwen/Qwen-72B
1. YES
2. YES