2024. 9. 18. 11:01ㆍNatural/Q
함수 \( f(x) = x^3 - 6x^2 + 10x \)의 정지점의 \( x \)-좌표를 찾으려면 함수의 도함수가 0이 되는 지점을 찾아야 한다.
단계:
1. 함수의 도함수를 구한다:
\[
f'(x) = 3x^2 - 12x + 10
\]
2. 도함수가 0이 되는 지점을 찾아 정지점을 구한다:
\[
3x^2 - 12x + 10 = 0
\]
3. 이 이차방정식을 이차 방정식의 공식을 사용하여 풉니다:
\[
x = \frac{-(-12) \pm \sqrt{(-12)^2 - 4(3)(10)}}{2(3)}
\]
간단히 하면:
\[
x = \frac{12 \pm \sqrt{144 - 120}}{6}
\]
\[
x = \frac{12 \pm \sqrt{24}}{6}
\]
\[
x = \frac{12 \pm 2\sqrt{6}}{6}
\]
\[
x = 2 \pm \frac{\sqrt{6}}{3}
\]
따라서, 정지점의 \( x \)-좌표는:
\[
x = 2 + \frac{\sqrt{6}}{3} \quad \text{와} \quad x = 2 - \frac{\sqrt{6}}{3}
\]
이다.
import numpy as np
import matplotlib.pyplot as plt
# Define the function and its derivative
def f(x):
return x**3 - 6*x**2 + 10*x
def f_prime(x):
return 3*x**2 - 12*x + 10
# Define the range of x values
x = np.linspace(0, 4, 400)
y = f(x)
# Solve for stationary points where f'(x) = 0
x_stationary1 = 2 + np.sqrt(6)/3
x_stationary2 = 2 - np.sqrt(6)/3
y_stationary1 = f(x_stationary1)
y_stationary2 = f(x_stationary2)
# Create the plot
plt.figure(figsize=(6,6))
plt.plot(x, y, 'w') # Plot the function in white
# Mark the stationary points with magenta dots
plt.scatter((x_stationary1, x_stationary2), (y_stationary1, y_stationary2), color='magenta', zorder=5)
# Add horizontal green dashed lines at the stationary points
plt.hlines(y=y_stationary1, xmin=0, xmax=x_stationary1, color='green', linestyles='dashed') # First stationary point
plt.hlines(y=y_stationary2, xmin=0, xmax=x_stationary2, color='green', linestyles='dashed') # Second stationary point
# Customize the graph appearance
plt.axhline(0, color='white', lw=0.5) # Add x-axis
plt.axvline(0, color='white', lw=0.5) # Add y-axis
plt.gca().set_facecolor('black') # Set background to black
plt.gca().spines['left'].set_color('white')
plt.gca().spines['bottom'].set_color('white')
plt.gca().tick_params(colors='red')
plt.title(r'$f(x) = x^3 - 6x^2 + 10x$', color='red', fontsize=16)
# Add text annotations for the stationary points
plt.text(x_stationary1, y_stationary1 + 0.5, r'$x = 2 + \frac{\sqrt{6}}{3}$', color='white', fontsize=12, ha='center')
plt.text(x_stationary2, y_stationary2 - 1, r'$x = 2 - \frac{\sqrt{6}}{3}$', color='white', fontsize=12, ha='center')
# Show the plot
plt.show()
plt.axhline(0, color='white', lw=0.5) # x축 추가
- plt.axhline(0): 그래프에 y=0y = 0인 수평선을 추가한다. 이 선이 x축을 형성하게 된다.
- color='white': 수평선을 흰색으로 그리겠다는 의미이다.
- lw=0.5: 선의 두께를 0.5로 설정한다. 값이 작을수록 선이 얇아진다.
plt.axvline(0, color='white', lw=0.5) # y축 추가
- plt.axvline(0): 그래프에 x=0x = 0인 수직선을 추가한다. 이 선이 y축을 형성하게 된다.
- color='white': 수직선을 흰색으로 설정한다.
- lw=0.5: 선의 두께를 0.5로 설정한다.
plt.gca().set_facecolor('black') # 배경을 검은색으로 설정
- plt.gca(): 현재의 그래프 축 객체(axes)를 가져온다. 이 객체는 그래프의 전체 설정을 담당한다.
- set_facecolor('black'): 그래프의 배경색을 검은색으로 설정한다. 기본적으로 흰색이지만, 이 명령을 사용하면 검은색으로 변경된다.
plt.gca().spines['left'].set_color('white')
- spines['left']: 그래프의 왼쪽 테두리(y축 라인)를 선택한다.
- set_color('white'): 왼쪽 테두리의 색을 흰색으로 설정한다.
plt.gca().spines['bottom'].set_color('white')
plt.gca().tick_params(colors='red')
tick_params(colors='white'): 그래프 축에 표시되는 틱(tick) 값의 색상을 흰색으로 설정한다. 이로써 x축과 y축 숫자들이 흰색으로 표시된다.
'Natural > Q' 카테고리의 다른 글
함수의 교차점 (0) | 2024.09.18 |
---|---|
리만 합 (0) | 2024.09.13 |
급수의 수렴 | 발산 (0) | 2024.09.13 |
미분의 정의를 사용하여 함수의 도함수를 구하는 과정 (0) | 2024.09.12 |
역함수 계산 (1) | 2024.07.26 |