Python sympy.cot() Method

Python SymPy Module:

SymPy is a Python symbolic mathematics library. It aims to be a full-featured computer algebra system (CAS) while keeping the code as basic(simple) as possible in order to be understandable and easily expandable. SymPy is entirely written in Python. SymPy is simple to use because it only depends on mpmath, a pure Python library for arbitrary floating-point arithmetic.

Rational and Integer are the numerical types defined by SymPy. A rational number is represented by the Rational class as a pair of two Integers, numerator and denominator, therefore Rational(1, 2) is 1/2, Rational(3, 2) is 3/2, and so on. Integer numbers are represented by the Integer class.

SymPy uses mpmath in the background, allowing it to execute arbitrary-precision arithmetic computations. Some special constants, such as exp, pi, and oo (Infinity), are thus considered as symbols and can be evaluated with arbitrary precision.

Installation:

pip install sympy

Python sympy.cot() Method:

We can determine the value of cot theta with the sympy.cot() method.

Syntax:

  sympy.cot()

Return Value:

The value of cot theta is returned by the cot() function.

sympy.cot() Method in Python

Method #1: Using cot() Function (Static Input)

Approach:

  • Import all the functions from sympy module using the import keyword
  • Pass some random theta value to the cot() function to get the cot value of the given angle theta.
  • Store it in a variable.
  • Print the cot value of the given angle theta.
  • The Exit of the Program.

Below is the implementation:

# Import all the functions from sympy module using the import keyword
from sympy import *

# Pass some random theta value to the cot() function to get the 
# cot value of the given angle theta.
# Store it in a variable.
rslt = cot(pi / 4)
    
# Print the cot value of the given angle theta
print("The cot value of the given angle theta = ", rslt)

Output:

The cot value of the given angle theta = 1

Method #2: Using cot() Function (User Input)

Approach:

  • Import all the functions from sympy module using the import keyword
  • Give the theta value(angle) as user input using the input() function and store it in a variable.
  • Pass the above-given theta value as an argument to the cot() function to get the cot value of the given angle theta.
  • Store it in a variable.
  • Print the cot value of the given angle theta.
  • The Exit of the Program.

Below is the implementation:

# Import all the functions from sympy module using the import keyword
from sympy import *

# Give the theta value(angle) as user input using input() function 
# and store it in a variable.
gvn_theta = input("Enter some random theta value = ")

# Pass the above given theta value as an argument to the cot() function to get the 
# cot value of the given angle theta.
# Store it in a variable.
rslt = cot(gvn_theta)
    
# Print the cot value of the given angle theta
print("The cot value of the given angle theta = ", rslt)

Output:

Enter some random theta value = pi/3
The cot value of the given angle theta = sqrt(3)/3