Check whether sequence converges or diverges in Python

Check whether sequence converges or diverges in Python

In this, we discuss the program to Check whether sequence converges or diverges in Python. We discuss three different examples here. Let's discuss all these one by one.

Example 1: Check whether the following sequence converges or diverges

Check whether the following sequence converges or diverges



Python Code:

from sympy import *
x = symbols(
'x')
r = limit((
1+1/x)**x,x,oo)
if (r==0):
print('The given sequence does not converge to any number')
else:
print('The given sequence converge to a number' + str(r))
print('limit of a given function')
print(r)
Output:
The given sequence converge to a number E
limit of a given function
E

Example 2: Check whether the following sequence converges or diverges





Python Code:
from sympy import *
x = symbols(
'x')
r = limit((x) **
2, x, oo)
if (r == oo):
print('The given sequence does not converge to any number')
else:
print('The given sequence converge to a number' + str(r))
print('limit of a given function')
print(r)
Output:
The given sequence does not converge to any number
limit of a given function
oo

Example 3: Check whether the following sequence converges or diverges

Check whether the following sequence converges or diverges




Python Code:
from sympy import *
x = symbols(
'x')
r = limit(sqrt(x+
1)- sqrt(x), x, oo)
if (r == oo):
print('The given sequence does not converge to any number')
else:
print('The given sequence converge to a number' + str(r))
print('limit of a given function')
print(r)
Output:
The given sequence converge to a number 0
limit of a given function
0