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.sec() Method:
We can determine the value of secant theta using the sec() method of the sympy module.
Syntax:
sympy.sec()
Return Value:
The value of secant theta is returned by the sec() function.
sympy.sec() Method in Python
Method #1: Using sec() Function (Static Input)
Approach:
- Import all the functions from sympy module using the import keyword
- Pass some random theta value to the sec() function to get the secant value of the given angle theta.
- Store it in a variable.
- Print the secant 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 sec() function to get the # secant value of the given angle theta. # Store it in a variable. rslt = sec(pi / 4) # Print the secant value of the given angle theta print("The secant value of the given angle theta = ", rslt)
Output:
The secant value of the given angle theta = sqrt(2)
Method #2: Using sec() Function (User Input)
Approach:
- Import all the functions from sympy module using the import keyword
- Give the theta value(angle) as user input using input() function and store it in a variable.
- Pass the above-given theta value as an argument to the sec() function to get the secant value of the given angle theta.
- Store it in a variable.
- Print the secant 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 sec() function to get the # secant value of the given angle theta. # Store it in a variable. rslt = sec(gvn_theta) # Print the secant value of the given angle theta print("The secant value of the given angle theta = ", rslt)
Output:
Enter some random theta value = pi/6 The secant value of the given angle theta = 2*sqrt(3)/3