기본 콘텐츠로 건너뛰기

pandas_ta를 적용한 통계적 인덱스 지표

극한의 특성과 계산

극한의 특성

$\lim_{x \to a}f(x), \;  \lim_{x \to a}g(x)$ 그리고 상수(constant) c사이에 다음 관계들이 성립합니다.

import numpy as np
import pandas as pd
from sympy import *
import matplotlib.pyplot as plt
x=symbols("x")
f=x**2+3*x
g=x**3+4*x+5
c=3
a=2
f
$\quad \color{blue}{x^{2} + 3 x}$
g
$\quad \color{blue}{x^{3} + 4 x + 5}$

1) $\displaystyle \lim_{x \to a}cf(x)=c\lim_{x \to a}f(x)$

limit(c*f, x, a)
30
c*limit(f, x, a)
30

2) $\displaystyle \lim_{x \to a}[f(x) \pm g(x)]=\lim_{x \to a}f(x) \pm \lim_{x \to a}g(x)$

limit(f+g, x, a)
31
limit(f, x, a)+limit(g, x, a)
31

3) $\displaystyle \lim_{x \to a}[f(x) g(x)]=\lim_{x \to a}f(x)  \lim_{x \to a}g(x)$

limit(f*g, x, a)
210
limit(f, x, a)*limit(g, x, a)
210

4) $\displaystyle \lim_{x \to a}\frac{f(x)}{g(x)}=\frac{\lim_{x \to a}f(x)}{\lim_{x \to a}g(x)}, \quad \lim_{x \to a}g(x)\neq 0$

limit(f/g, x, a)
$\quad \color{blue}{\displaystyle \frac{1}{21}}$
limit(f, x, a)/limit(g, x, a)
$\quad \color{blue}{\displaystyle \frac{1}{21}}$

5) $\lim_{x \to a}[f(x)]^n=[\lim_{x \to a}f(x)]^n, \quad n \in\;$실수

limit(f**c, x, a)
1000
limit(f, x, a)**c
1000

6) 5)와 같은 특성으로 n 제곱근에서도 성립합니다.

$$\lim_{x \to a}\sqrt[n]{f(x)}=\sqrt[n]{\lim_{x \to a}f(x)}, \quad n \in\; \text{실수}$$
N(limit(f**(1/c), x, a), 4)
2.154
N((limit(f, x, a))**(1/c), 4)
2.154

7) 실수의 극한값은 그 자신이 됩니다.

$$\lim_{x \to a} c = c$$
limit(c, x, a)
3

8)$\displaystyle \lim_{x \to a}x=a$
a=2에서의 극한값은 2입니다.<\p>

f=x
a=np.r_[np.linspace(1.9, 1.999, 5), np.linspace(2.001, 2.1, 5)]
y=np.array([f.subs(x, i) for i in a], dtype=float)
np.array([a, y]).T
array([[1.9    , 1.9    ],
       [1.92475, 1.92475],
       [1.9495 , 1.9495 ],
       [1.97425, 1.97425],
       [1.999  , 1.999  ],
       [2.001  , 2.001  ],
       [2.02575, 2.02575],
       [2.0505 , 2.0505 ],
       [2.07525, 2.07525],
       [2.1    , 2.1    ]])
limit(f,x, 2)
2

9) $\displaystyle \lim_{x \to a}x^n=a^n$

f=x**4
a=np.r_[np.linspace(1.9, 1.999, 5), np.linspace(2.001, 2.1, 5)]
y=np.array([f.subs(x, i) for i in a], dtype=float)
np.array([a, y]).T
array([[ 1.9       , 13.0321    ],
       [ 1.92475   , 13.7245247 ],
       [ 1.9495    , 14.4441822 ],
       [ 1.97425   , 15.19177735],
       [ 1.999     , 15.96802399],
       [ 2.001     , 16.03202401],
       [ 2.02575   , 16.84005053],
       [ 2.0505    , 17.6782428 ],
       [ 2.07525   , 18.54734243],
       [ 2.1       , 19.4481    ]])
limit(f,x, 2)
16

예 1)

$$\lim_{x \to -2}(3x^2+5x-9)= \lim_{x \to -2}3x^2+\lim_{x \to -2}5x+\lim_{x \to -2}-9$$
f=3*x**2+5*x-9
limit(f, x, -2)
-7
limit(3*x**2, x, -2)+limit(5*x, x, -2)+limit(-9, x, -2)
-7

예 2)

$$\lim_{x \to 2}\frac{t^2+4t-12}{t^2-2t}$$

위 함수는 x=0에서 분모가 0이 되므로 정의할 수 없습니다. 그러므로 0을 기준으로 별도의 영역에서 함수의 형태는 다음과 같습니다.

t=symbols("t")
f=(t**2+4*t-12)/(t**2-2*t)
f
$$\quad \color{blue}{\displaystyle \frac{t^{2} + 4 t - 12}{t^{2} - 2 t}}$$
x1=np.linspace(-3, -0.1, 100)
x2=np.linspace(0.1, 3, 100)
y1=np.array([f.subs(t, i) for i in x1], dtype="float")
y2=np.array([f.subs(t, i) for i in x2], dtype="float")
plt.figure(dpi=80)
plt.plot(x1, y1, label="t > 0")
plt.plot(x2, y2, label="t < 0")
plt.scatter(2, 4, color="green")
plt.xlabel("t", size=12, weight="bold")
plt.ylabel("f(t)", size=12, weight="bold")
plt.legend(loc='best')
plt.text(-3, 40, r"f(t)=$\mathbf{\frac{t^{2} + 4 t - 12}{t^{2} - 2 t}}$", size="13")
plt.show()

위 그림에서와 나타낸 것과 같이 t=2에 대한 f(t)값은 4입니다. 이 값은 f(t)를 인수분해에 의해 간단한 형태로 변환한 뒤 계산한 결과입니다.

f1=f.simplify()
f1
$\quad \color{blue}{\displaystyle \frac{t + 6}{t}}$
f1.subs(t, 2)
4

이 결과는 limit() 함수를 적용한 경우와 같습니다.

limit(f, x, 2)
4

예 3)

$$\lim_{x \to 0}\frac{2(-3+x)^2-18)}{x}$$
f=(2*(-3+x)**2-18)/x
limit(f, x, 0)
-12

댓글

이 블로그의 인기 게시물

[Linear Algebra] 유사변환(Similarity transformation)

유사변환(Similarity transformation) n×n 차원의 정방 행렬 A, B 그리고 가역 행렬 P 사이에 식 1의 관계가 성립하면 행렬 A와 B는 유사행렬(similarity matrix)이 되며 행렬 A를 가역행렬 P와 B로 분해하는 것을 유사 변환(similarity transformation) 이라고 합니다. $$\tag{1} A = PBP^{-1} \Leftrightarrow P^{-1}AP = B $$ 식 2는 식 1의 양변에 B의 고유값을 고려한 것입니다. \begin{align}\tag{식 2} B - \lambda I &= P^{-1}AP – \lambda P^{-1}P\\ &= P^{-1}(AP – \lambda P)\\ &= P^{-1}(A - \lambda I)P \end{align} 식 2의 행렬식은 식 3과 같이 정리됩니다. \begin{align} &\begin{aligned}\textsf{det}(B - \lambda I ) & = \textsf{det}(P^{-1}(AP – \lambda P))\\ &= \textsf{det}(P^{-1}) \textsf{det}((A – \lambda I)) \textsf{det}(P)\\ &= \textsf{det}(P^{-1}) \textsf{det}(P) \textsf{det}((A – \lambda I))\\ &= \textsf{det}(A – \lambda I)\end{aligned}\\ &\begin{aligned}\because \; \textsf{det}(P^{-1}) \textsf{det}(P) &= \textsf{det}(P^{-1}P)\\ &= \textsf{det}(I)\end{aligned}\end{align} 유사행렬의 특성 유사행렬인 두 정방행렬 A와 B는 'A ~ B' 와 같...

유리함수 그래프와 점근선 그리기

내용 유리함수(Rational Function) 점근선(asymptote) 유리함수 그래프와 점근선 그리기 유리함수(Rational Function) 유리함수는 분수형태의 함수를 의미합니다. 예를들어 다음 함수는 분수형태의 유리함수입니다. $$f(x)=\frac{x^{2} - 1}{x^{2} + x - 6}$$ 분수의 경우 분모가 0인 경우 정의할 수 없습니다. 이와 마찬가지로 유리함수 f(x)의 정의역은 분모가 0이 아닌 부분이어야 합니다. 그러므로 위함수의 정의역은 분모가 0인 부분을 제외한 부분들로 구성됩니다. sympt=solve(denom(f), a); asympt [-3, 2] $$-\infty \lt x \lt -3, \quad -3 \lt x \lt 2, \quad 2 \lt x \lt \infty$$ 이 정의역을 고려해 그래프를 작성을 위한 사용자 정의함수는 다음과 같습니다. def validX(x, f, symbol): ① a=[] b=[] for i in x: try: b.append(float(f.subs(symbol, i))) a.append(i) except: pass return(a, b) #x는 임의로 지정한 정의역으로 불연속선점을 기준으로 구분된 몇개의 구간으로 전달할 수 있습니다. #그러므로 인수 x는 2차원이어야 합니다. def RationalPlot(x, f, sym, dp=100): fig, ax=plt.subplots(dpi=dp) # ② for k in x: #③ x4, y4=validX(k, f, sym) ax.plot(x4, y4) ax.spines['left'].set_position(('data', 0)) ax.spines['right...

부분분수의 미분

내용 방법 1 방법 2 방법 3 부분분수의 미분 분수의 미분은 일정한 공식 을 적용하여 계산할 수 있습니다. 그러나 분수 자체가 단순한 표현으로 이루어지지 않았다면 미분 과정이나 결과는 매우 복잡할 수 있습니다. 만약 복잡한 분수 함수를 간단한 분수들로 분해할 수 있다면 계산이 보다 간편해질 것입니다. 이와 같이 분해된 간단한 분수들을 부분분수 라고 합니다. 예를 들어 다음 두 분수의 합을 계산해 봅니다. $$\begin{align} \frac{1}{x+1}+\frac{2}{x-1}&=\frac{x-1+2(x+1)}{(x+1)(x-1)}\\ &=\frac{3x+1}{x^2-1} \end{align}$$ 위 과정은 3개 이상의 여러 분수에서도 이루어질 수 있습니다. 또한 역으로 진행될 수 있습니다. 즉, 분수를 부분 분수로 분할할 수 있습니다. 그러나 이러한 과정은 대수분수 (분자의 가장 큰 차수가 분모의 최고의 차수보다 작은 분수)에서만 이루어질 수 있습니다. 예를 들어 $\displaystyle \frac {x^2+2}{x^2-1}$의 경우는 분자와 분모의 차수는 2차로 같습니다. 이러한 경우 다음과 같이 분리할 수 있습니다. $$\frac{x^2+2}{x^2-1}=1+\frac{3}{x^2-1}$$ 위의 식 중 $\displaystyle \frac{3}{x^2-1}$은 분자의 차수가 분모의 차수 보다 낮은 대수 분수이므로 부분 분수로 분리할 수 있습니다. 이와같이 부분 분수로 분해하는 방법은 다음과 같이 몇 가지로 구분할 수 있습니다. 방법 1 위 예의 결과 $\displaystyle \frac{3x+1}{x^2-1}$의 경우를 역으로 생각해 봅니다. 분모의 인수분해가 가능하면 그 분모의 인수에 의해 다음과 같이 분해할 수 있습니다. $$\begin{align} \frac{3x+1}{x^2-1}&=\frac{3x+1}{(x+1)(x-1)}\\ &=\frac{A}{x+1...