当前位置:   article > 正文

【高数:3 无穷小与无穷大】_sympy中正负无穷大写法

sympy中正负无穷大写法

参考书籍:毕文斌, 毛悦悦. Python漫游数学王国[M]. 北京:清华大学出版社,2022.

1 无穷小与无穷大

无穷大在sympy中用两个字母o表示无穷大,正无穷大为sy.oo,负无穷大为-sy.oo

import sympy as sy
x=sy.oo
print(1/x)
  • 1
  • 2
  • 3
>>>0
  • 1

lim ⁡ x → 0 − 1 x \lim_{x \to 0^-} \frac{1}{x} limx0x1

x=sy.symbols('x')
print(sy.limit(1/x,x,0,dir='-'))
  • 1
  • 2
>>>-oo
  • 1

2 极限运算法则

lim ⁡ x → 3 x − 3 x 2 − 9 \lim_{x \to 3} \frac{x-3}{x^2-9} limx3x29x3

import sympy as sy
x=sy.symbols('x')
print(sy.limit((x-3)/(x**2-9),x,3,dir='+-'))
  • 1
  • 2
  • 3

lim ⁡ x → 1 2 x − 3 x 2 − 5 x + 4 \lim_{x \to 1} \frac{2x-3}{x^2-5x+4} limx1x25x+42x3

x=sy.symbols('x')
print(sy.limit((2*x-3)/(x**2-5*x+4),x,1,dir='-'))
print(sy.limit((2*x-3)/(x**2-5*x+4),x,1))
  • 1
  • 2
  • 3
>>>-oo, oo 故趋于无穷时极限为无穷oo
  • 1

lim ⁡ x → ∞ 3 x 3 + 4 X 2 + 2 7 x 3 + 5 x 2 − 3 \lim_{x \to \infty} \frac{3x^3+4X^2+2}{7x^3+5x^2-3} limx7x3+5x233x3+4X2+2

x=sy.symbols('x')
print(sy.limit((3*x**3+4*x**2+2)/(7*x**3+5*x**2-3),x,sy.oo,dir='-'))
print(sy.limit((3*x**3+4*x**2+2)/(7*x**3+5*x**2-3),x,-sy.oo,dir='+'))
  • 1
  • 2
  • 3
>>>3/7,3/7 故趋于无穷时极限为3/7
  • 1

当分子分母极限都不存在时, lim ⁡ x → ∞ sin ⁡ x x \lim_{x \to \infty} \frac{\sin x}{x} limxxsinx

x=sy.symbols('x')
y=sy.sin(x)/x
print(sy.limit(y,x,sy.oo,dir='+'))
print(sy.limit(y,x,-sy.oo,dir='+'))
  • 1
  • 2
  • 3
  • 4
>>>0 , 0 故趋于无穷时极限为0
  • 1

3 极限存在原则

eg1: lim ⁡ x → 0 sin ⁡ x x \lim_{x \to 0} \frac{\sin x}{x} limx0xsinx

import sympy as sy
x=sy.symbols('x')
lim=sy.limit(sy.sin(x)/x,x,0,dir='+-')
print(lim)
  • 1
  • 2
  • 3
  • 4
>>>1
  • 1

eg2: lim ⁡ x → 0 arcsin ⁡ x tan ⁡ x \lim_{x \to 0} \frac{\arcsin x}{\tan x} limx0tanxarcsinx

x=sy.symbols('x')
print(sy.limit(sy.asin(x)/sy.tan(x),x,0,dir='+-'))  #sy.asin()指arcsin函数
  • 1
  • 2
>>>1
  • 1

eg3: lim ⁡ x → 0 1 − cos ⁡ x x 2 \lim_{x \to 0} \frac{1- \cos x}{x^2} limx0x21cosx

x=sy.symbols('x')
print(sy.limit((1-sy.cos(x))/(x**2),x,0,dir='+-'))
  • 1
  • 2
>>>1/2
  • 1

eg4: lim ⁡ x → 0 ( 1 + x ) 1 x \lim_{x \to 0} (1+x)^{\frac{1}{x}} limx0(1+x)x1

x=sy.symbols('x')
lim=sy.limit((1+x)**(1/x),x,0,dir='+-')
print(lim)
  • 1
  • 2
  • 3
>>>E
  • 1

eg5: lim ⁡ x → ∞ ( 1 + 1 x ) x \lim_{x \to \infty} (1+\frac{1}{x})^x limx(1+x1)x

x=sy.symbols('x')
lim=sy.limit((1+1/x)**x,x,sy.oo,dir='-')
print(lim)
print(lim.round(3))
print(sy.limit((1+1/x)**x,x,-sy.oo))
  • 1
  • 2
  • 3
  • 4
  • 5
>>>E, 2.718, E
  • 1

eg6: 说明数列 2 , 2 + 2 , 2 + 2 + 2 \sqrt{2} , \sqrt{2+\sqrt{2}},\sqrt{2+\sqrt{2+\sqrt{2}}} 2 ,2+2 ,2+2+2 ,···的极限存在

#用函数的递归机制定义数列
def a_complex_series(n):
    #退出条件
    if n<=0:return 2**0.5
    #一个函数如果调用自身,则这个函数就是一个递归函数
    return (2.0+a_complex_series(n-1))**0.5
#绘制前20个数的散点图
import matplotlib.pyplot as plt
import numpy as np
x=[]
y=[]
for i in range(20):
    x.append(i)
    y.append(a_complex_series(i))
print(np.array(y))
plt.scatter(x,y)
plt.show()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
>>>[1.41421356 1.84775907 1.96157056 1.99036945 1.99759091 1.99939764
1.9998494  1.99996235 1.99999059 1.99999765 1.99999941 1.99999985
 1.99999996 1.99999999 2.         2.         2.         2.
2.         2.        ]
  • 1
  • 2
  • 3
  • 4

在这里插入图片描述
故极限为2

4 趋于无穷小的比较

eg1: lim ⁡ x → 0 tan ⁡ 2 x sin ⁡ 5 x \lim_{x \to 0} \frac{\tan 2x}{\sin 5x} limx0sin5xtan2x

from sympy import limit,sin,cos,tan,symbols #从sympy中仅导入这几个函数
x=symbols('x')
example_1=tan(2*x)/sin(5*x)
result=limit(example_1,x,0,dir='+-')
print(result)
  • 1
  • 2
  • 3
  • 4
  • 5
>>>2/5
  • 1

eg2: lim ⁡ x → 0 sin ⁡ x x 3 + 3 x \lim_{x \to 0} \frac{\sin x}{x^3+3x} limx0x3+3xsinx

x=symbols('x')
example_2=sin(x)/(x**3+3*x)
result=limit(example_2,x,0,dir='+-')
print(result)
  • 1
  • 2
  • 3
  • 4
>>>1/3
  • 1

eg3: lim ⁡ x → 0 ( 1 + x 2 ) 1 / 3 − 1 cos ⁡ x − 1 \lim_{x \to 0} \frac{(1+x^2)^{1/3}-1}{\cos x-1} limx0cosx1(1+x2)1/31

x=symbols('x')
example_3=((1+x**2)**(1/3)-1)/(cos(x)-1)
result=limit(example_3,x,0,dir='+-')
print(result)
  • 1
  • 2
  • 3
  • 4
>>>-2/3
  • 1
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/927425
推荐阅读
相关标签
  

闽ICP备14008679号