개발일기
원의 방정식의 적분, 삼각치환법 본문
$x^2+y^2=r^2$의 넓이를 알아보도록 하자
음함수 형태이니 $y=f(x)$꼴로 바꾸면 2개가 나온다
\[ y=\begin{cases} \sqrt{r^2-x^2} \\ -\sqrt{r^2-x^2} \end{cases} \]
윗놈 적분하든 아랫놈 적분하든 어차피 하나 적분해서 2배 하면 되니 부호 없는 윗놈으로 하자
식은 $\displaystyle \frac{1}{2}S=\int_{-r}^{r}{\sqrt{r^2-x^2}dx}$로 쓸 수 있는데, 루트 안에 제곱이 들어간 기괴한 형태라 함부로 적분할 수 없다.
$r^2-x^2=t$로 두어도, $-2xdx=dt$이므로 $x$를 없앨 수 없어 적분을 진행할 수 없고, 두 식이 곱해진 형태도 아니므로 부분적분도 쓰지 못 한다
$x=r\sin\theta$로 치환하기
이럴 때 $x=r\sin\theta$로 두어보자. $dx=r\cos\theta d\theta$이고, $r^2-x^2=r^2(1-\sin^2\theta)=r^2\cos^2\theta$이므로 루트도 쉽게 벗길 수 있다.
이 때, $\cos\theta<0$일 경우 루트를 벗기기 곤란할 수도 있다.
하한이 $x=r\sin\theta=-r$이고, 상한이 $x=r\sin\theta=r$인데, $\theta$의 범위를 $ \displaystyle -\frac{1}{2}\pi\leq\theta\leq\frac{1}{2}\pi$로 둔다면 $\cos\theta\geq0$이고, 하한과 상한도 딱 들어맞는다.
따라서 식을 $ \displaystyle \frac{1}{2}S=\int_{-\frac{\pi}{2}}^{\frac{\pi}{2}} r^2 \cos^2\theta d\theta$와 같이 바꿀 수 있다.
(루트를 안 벗긴 게 아니다, 루트는 제대로 벗겼다. 적분변수에 주의하자)
적분을 간편하게 진행하기 위해서 삼각함수의 반각공식을 이용해주자
$ \displaystyle \cos^2\frac{\theta}{2}=\frac{1+\cos\theta}{2}$이므로, $ \displaystyle \cos^2\theta=\frac{1+\cos2\theta}{2}$이다.
식을 다시 정리한다면 $ \displaystyle \frac{r^2}{2}\int_{-\frac{1}{2}\pi}^{\frac{1}{2}\pi} (1+\cos2\theta) d\theta$이다.
$ \displaystyle \frac{1}{2}S=\frac{r^2}{2} \bigg[x+\frac{\sin2\theta}{2}\bigg]_{-\frac{1}{2}\pi}^{\frac{1}{2}\pi}= \frac{r^2}{2} (\pi+0)=\frac{1}{2}\pi r^2$
$ \displaystyle \therefore \frac{1}{2}S=\frac{1}{2}\pi r^2$가 반원의 넓이이므로 $S=\pi r^2$이다.
$x=r\cos\theta$로 치환하기
근데 개인적으로 $x=r\sin\theta$로 두는 건 의미상 조금 더럽다고 느끼기 때문에 $x=r\cos\theta$로 치환해서 적분을 진행하는 방법도 작성해보겠다.
다시 원래의 적분식으로 돌아가서,
$\displaystyle \frac{1}{2}S=\int_{-r}^{r}{\sqrt{r^2-x^2}dx}$
$x=r\cos\theta$로 두고, $0\leq\theta\leq\pi$로 두어보자.
사실 $x=r\sin\theta$가 마음에 들지 않는 이유가 시각적으로 떠올리기가 쉽지 않고, 순전히 수식에만 의존하여 전개하는 방식이라서 싫어했는데, $x=r\cos\theta$로 두면 반원 중심에서 시초선 벡터 $\vec{v}=(r,0)$가 반원에서 $\pi$만큼 회전하는 모습을 떠올리기가 쉽다. 나만 그런가. 어쨋든 본론으로 돌아가면
$dx=-r\sin\theta d\theta$이고, $x=r\cos\theta=-r$일 때 $\theta=\pi$, $x=r\cos\theta=r$일 때 $\theta=0$이다.
식을 다시 작성하면 $\displaystyle \frac{1}{2}S=\int_{\pi}^{0} \sqrt{r^2(1-cos^2\theta)}\times(-r\sin\theta)d\theta= \int_{0}^{\pi} r^2\sin^2\theta d\theta$로 정리된다.
($0\leq\theta\leq\pi$에서 $\sin\theta\geq0$인 것, 부호와 상한/ 하한의 변환에 주의하자)
이 뒤는 위에 했던 것과 마찬가지로 똑같이 진행해줄 수 있다.
$ \displaystyle \sin^2\theta=\frac{1-\cos2\theta}{2}$이다.
$ \displaystyle r^2 \int_{0}^{\pi}\sin^2\theta d\theta = \frac{r^2}{2} \int_{0}^{\pi}(1-\cos2\theta) d\theta $
$ \displaystyle \frac{1}{2}S=\frac{r^2}{2} \bigg[ x-\frac{\sin2\theta}{2} \bigg]_{0}^{\pi}=\frac{r^2}{2}(\pi-0)=\frac{1}{2}\pi r^2$
정리해주면 $S=\pi r^2$이다.
타원의 방정식 $ \displaystyle \frac{x^2}{a^2}+\frac{y^2}{b^2}=1$의 적분
타원도 원이니 똑같이 구해보자. $y=f(x)$꼴로 정리해주면 다음과 같다.
$ \displaystyle y=b\sqrt{1-\frac{x^2}{a^2}}=\frac{b}{a}\sqrt{a^2-x^2}$
따라서 $\displaystyle \frac{1}{2}S=\int_{-a}^{a}\frac{b}{a}\sqrt{a^2-x^2}dx$이다.
어... 우린 이미 저 루트 부분의 적분값을 알고 있다. $ \displaystyle \frac{1}{2}\pi a^2$이다.
정리하면 $ \displaystyle \frac{1}{2}S=\frac{b}{a}\times\frac{1}{2}\pi a^2=\frac{1}{2}\pi ab$이다.
따라서 $S=\pi ab$이다.
$a=b=r$이면 $S=\pi r^2$이므로 기존에 구한 원의 넓이와도 들어맞는다. 끝.
몬테카를로 방법
랜덤 점 찍어서 비율로 구하는 방식이다.
당연히 사람 손으로는 못 하고 python 코드를 통해 매우 간단하게 구현해볼 수 있다.
import random
point_num = input("샘플링할 점의 개수 : ")
radius = input("반지름 : ")
# 입력하지 않으면 1000000, 1로 처리
if point_num.isdigit():point_num=int(point_num)
else: point_num = 1000000
if radius.isdigit():radius=int(radius)
else: radius = 1
point_num_list = [0, 0, 0] # 원 밖에 있음, 원 위에 있음, 원 안에 있음
print("샘플링할 점의 개수에 따라 시간이 걸릴 수 있습니다.")
for i in range(point_num):
# (-radius, radius) 범위로 균등하게 점을 샘플링
random_point = (random.uniform(-radius, radius), random.uniform(-radius, radius))
distance = (random_point[0]**2 + random_point[1]**2)**(1/2)
if distance > radius:
point_num_list[0] += 1 # 원 밖
elif distance == radius:
point_num_list[1] += 1 # 원 위
else:
point_num_list[2] += 1 # 원 안
total_points = point_num_list[0] + point_num_list[1] + point_num_list[2]
ratio=point_num_list[2] / total_points
print("원의 밖,
위,
안에
있는 점의 개수:", point_num_list[0],point_num_list[1],point_num_list[2])
print("원 안에 있는 점의 비율:", ratio)
print("근사된 원의 넓이:",ratio*4*(radius**2))
print("근사된 원주율의
값:",ratio*4)
'공부' 카테고리의 다른 글
| 오일러-라그랑주 방정식, 최소 작용의 원리 (0) | 2025.04.21 |
|---|---|
| 화학#2 (0) | 2025.02.03 |
| 삼각함수의 직교성과 푸리에 변환 (0) | 2025.01.30 |
| 오일러 공식의 증명에 대하여 (0) | 2025.01.13 |
| 화학#1 (1) | 2024.12.29 |