本博文源于python实现高等数学基础,详细讲述了,如何用python中的sympy库求一点或无穷区间的极限。并附有多道例题可供修改,复制。可谓是收藏佳作。
数学运算 | Python函数命令 |
---|---|
lim x->a+ | limit(f,x,a) |
lim x->a- | limit(f,x,a,dir=’-’) |
lim x->a | limit(f,x,a,dir=’+’) |
lim x-> + ∞ +\infty +∞ | limit(f,x,oo) |
lim x-> − ∞ -\infty −∞ | limit(f,x,-oo) |
1.求下列函数的极限
( 1 ) lim x → 1 ( 1 x + 1 − 2 x 3 − 2 ) (1)\lim\limits_{
{x}\to{1}}(\frac{1}{x+1}-\frac{2}{x^3-2}) (1)x→1lim(x+11−x3−22)
( 2 ) lim x → + ∞ ( 3 − 2 x + 3 ) n (2)\lim\limits_{
{x}\to{+\infty}}(\frac{3-2}{x+3})^n (2)x→+∞lim(x+33−2)n
>>> from sympy import *
>>> x = symbols('x')
>>> limit(1/(x+1)-2/(x**3-2),x,1)
5/2
>>>
>>> from sympy import *
>>> x,n = symbols('x n')
>>> print(limit(((3*x-2)/(x+3))**n,x,oo))
3**n
>>>
2.考察函数 f ( x ) = sin x x f(x)=\frac{\sin{x}}{x} f(x)=xsinx在x->0时的变化趋势,并求极限
import matplotlib.pyplot as plt
from numpy import *
x = arange(-5*pi,5*pi,0.01)
y = sin(x)/x
plt.figure() # 打开窗口
plt.plot(x,y) # 画出图像
plt.grid(True) # 网格线开始
plt.show() # 展示show出来
>>> from sympy import *
>>> x = symbols('x')
>>> y = sin(x)/x
>>> print(limit(y,x,0))
1
3.考察函数 f ( x ) = ( 1 + 1 x ) x f(x)=(1+\frac{1}{x})^x f(x)=(1+x1)x在x-> ∞ \infty ∞时的变化趋势,并求其极限.
import matplotlib.pyplot as plt
from numpy import *
x1 = arange(-100,-2,0.01)
x2 = arange(0,100,0.01)
y1 = (1+1/x1)**x1
y2 = (1+1/x2)**x2
plt.figure()
plt.plot(x1,y1,x2,y2)
plt.grid(True)
plt.show()