기본 콘텐츠로 건너뛰기

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' 와 같...

[sympy] Sympy객체의 표현을 위한 함수들

Sympy객체의 표현을 위한 함수들 General simplify(x): 식 x(sympy 객체)를 간단히 정리 합니다. import numpy as np from sympy import * x=symbols("x") a=sin(x)**2+cos(x)**2 a $\sin^{2}{\left(x \right)} + \cos^{2}{\left(x \right)}$ simplify(a) 1 simplify(b) $\frac{x^{3} + x^{2} - x - 1}{x^{2} + 2 x + 1}$ simplify(b) x - 1 c=gamma(x)/gamma(x-2) c $\frac{\Gamma\left(x\right)}{\Gamma\left(x - 2\right)}$ simplify(c) $\displaystyle \left(x - 2\right) \left(x - 1\right)$ 위의 예들 중 객체 c의 감마함수(gamma(x))는 확률분포 등 여러 부분에서 사용되는 표현식으로 다음과 같이 정의 됩니다. 감마함수는 음이 아닌 정수를 제외한 모든 수에서 정의됩니다. 식 1과 같이 자연수에서 감마함수는 factorial(!), 부동소수(양의 실수)인 경우 적분을 적용하여 계산합니다. $$\tag{식 1}\Gamma(n) =\begin{cases}(n-1)!& n:\text{자연수}\\\int^\infty_0x^{n-1}e^{-x}\,dx& n:\text{부동소수}\end{cases}$$ x=symbols('x') gamma(x).subs(x,4) $\displaystyle 6$ factorial 계산은 math.factorial() 함수를 사용할 수 있습니다. import math math.factorial(3) 6 a=gamma(x).subs(x,4.5) a.evalf(3) 11.6 simpilfy() 함수의 알고리즘은 식에서 공통사항을 찾아 정리하...

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

내용 유리함수(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...