Python Tutorial

Introduction Python Features Python Applications System requirements for Python Python Installation Python Basics Python Variables Python Data Types Python IDE Python Keywords Python Operators Python Comments Python Pass Statement

Python Conditional Statements

Python if Statement Python elif Statement Python If-else statement Python Switch Case

Python Loops

Python for loop Python while loop Python Break Statement Python Continue Statement Python Goto Statement

Python Arrays

Python Array Python Matrix

Python Strings

Python Strings Python Regex

Python Built-in Data Structure

Python Lists Python Tuples Python Lists vs Tuples Python Dictionary Python Sets

Python Functions

Python Function Python min() function Python max() function Python User-define Functions Python Built-in Functions Anonymous/Lambda Function in Python

Python File Handling

Python File Handling Python Read CSV Python Write CSV Python Read Excel Python Write Excel Python Read Text File Python Write Text File Read JSON File in Python

Python Exception Handling

Python Exception Handling Python Errors and exceptions Python Assert

Python OOPs Concept

OOPs Concepts in Python Classes & Objects in Python Inheritance in Python Polymorphism in Python Python Encapsulation Python Constructor Static Variables in Python Abstraction in Python

Python Iterators

Iterators in Python Yield Statement In Python

Python Generators

Python Generator

Python Decorators

Python Decorator

Python Functions and Methods

Python Built-in Functions Python String Methods Python List Methods Python Dictionary Methods Python Tuple Methods Python Set Methods

Python Modules

Python Modules Python Datetime Module Python Calendar Module  

Python MySQL

Python MySQL Python MySQL Update Operation Python MySQL Delete Operation

Python MongoDB

Python MongoDB

Python Data Structure Implementation

Python Stack Python Queue Python Hash Table Python Graph

Python Advance Topics

Speech Recognition in Python Face Recognition in Python Python Rest API Python Command Line Arguments Python JSON Python Virtual Environment Type Casting in Python Collections in python Python Enumerate Python Debugger Python DefaultDict

Misc

Python PPTX Python Pickle Python Seaborn Python Coroutine Python EOL Python Infinity Python math.cos and math.acos function Python Project Ideas Based On Django Reverse a String in Python Reverse a Number in Python Python Word Tokenizer Python Trigonometric Functions Python try catch exception GUI Calculator in Python Implementing geometric shapes into the game in python Installing Packages in Python Python Try Except Python Sending Email Socket Programming in Python Python CGI Programming Python Data Structures Python abstract class Python Compiler Python K-Means Clustering List Comprehension in Python3 NSE Tools In Python Operator Module In Python Palindrome In Python Permutations in Python Pillow Python introduction and setup Python Functionalities of Pillow Module Python Argmin Python whois Python JSON Schema Python lock Return Statement In Python Reverse a sentence In Python tell() function in Python Why learn Python? Write Dictionary to CSV in Python Write a String in Python Binary Search Visualization using Pygame in Python Latest Project Ideas using Python 2022 Closest Pair of Points in Python ComboBox in Python Python vs R Python Ternary Operators Self in Python Python vs Java Python Modulo Python Packages Python Syntax Python Uses Python Logical Operators Python Multiprocessing Python History Difference between Input() and raw_input() functions in Python Conditional Statements in python Confusion Matrix Visualization Python Python Algorithms Python Modules List Difference between Python 2 and Python 3 Is Python Case Sensitive Method Overloading in Python Python Arithmetic Operators Design patterns in python Assignment Operators in Python Is Python Object Oriented Programming language Division in Python Python exit commands Continue And Pass Statements In Python Colors In Python Convert String Into Int In Python Convert String To Binary In Python Convert Uppercase To Lowercase In Python Convert XML To JSON In Python Converting Set To List In Python Covariance In Python CSV Module In Python Decision Tree In Python Difference Between Yield And Return In Python Dynamic Typing In Python Abstract design pattern in python Builder design pattern in python Prototype design pattern in Python Creational design patterns in Python

How to

How to convert integer to float in Python How to reverse a string in Python How to take input in Python How to install Python in Windows How to install Python in Ubuntu How to install PIP in Python How to call a function in Python How to download Python How to comment multiple lines in Python How to create a file in Python How to create a list in Python How to declare array in Python How to clear screen in Python How to convert string to list in Python How to take multiple inputs in Python How to write a program in Python How to compare two strings in Python How to create a dictionary in Python How to create an array in Python How to update Python How to compare two lists in Python How to concatenate two strings in Python How to print pattern in Python How to check data type in python How to slice a list in python How to implement classifiers in Python How To Print Colored Text in Python How to develop a game in python How to print in same line in python How to create a class in python How to find square root in python How to import numy in python How to import pandas in python How to uninstall python How to upgrade PIP in python How to append a string in python How to open a file in python

Sorting

Python Sort List Sort Dictionary in Python Python sort() function Python Bubble Sort

Programs

Factorial Program in Python Prime Number Program in Python Fibonacci Series Program in Python Leap Year Program in Python Palindrome Program in Python Check Palindrome In Python Calculator Program in Python Armstrong Number Program in Python Python Program to add two numbers Anagram Program in Python Even Odd Program in Python GCD Program in Python Python Exit Program Python Program to check Leap Year Operator Overloading in Python Pointers in Python Python Not Equal Operator Raise Exception in Python Salary of Python Developers in India What is a Script in Python Singleton design pattern in python

Python Trigonometric Functions

Before jumping right into the functions and how to use them we need to know what do trigonometric functions mean and how many functions does python has.

What are Trigonometric functions?

Trigonometric functions are the functions of an angle of a triangle. These trigonometric functions definite connection between the angles of a triangle.

Trigonometric Functions in Python

Python math module (it comprises of the mathematical functions) has plenty of trigonometric functions. Trigonometric functions can be used by using “import math”.

math.function_name(parameter)

# or import the math module

Import math

Methods to convert degrees to radians and radians to a degree:

Degrees(value): This method helps convert the value into degrees from radians.

Example:

import math

print(math.degrees((math.pi/2)))

Output

90.0

Radians(value): This method helps convert the value into radians from degrees.

Example:

import math

print(math.radians(60))

Output:

1.0471975511965976

Types of Functions in python

1. Sin(x) Function

Sin(x) returns sine value which is passed as an argument.

2. Cos(x) Function

Cos(x) returns cosine value which is passed as an argument.

3. Tan(x) Function

Tan(x) returns a tangent value of the parameter which is passed, that is angle of sine/cosine .” X” should be an angle represented as a radian.

Example :

import math

print(math.sin(math.pi/3))

print(math.tan(math.pi/3))

print(math.cos(math.pi/6))

Output:

0.8660254037844386

1.7320508075688767

0.8660254037844387

Note: Input in trigonometric functions in python are represented in radians.

1. asin(X) Function

asin(X) returns the inverse value of sine, called as “arc sine of a complex number”. -1 to 1 should be the range and represented in radians. Output a floating-point number.

2. acos(x) Function

acos(x) Function returns the inverse value of cosine, called “arc cosine of a complex number”. -1 to 1 should be the range and represented in radians. Output is a floating-point number.

3. atan(x) Function

atan(x) Function returns the inverse value of tan, called as “arc tangent of the complex number”. -1 to 1 should be the range and represented as

(math.sin(math.pi / 4)) / (math.cos(math.pi / 4)). Output is floating point number.

Example:

import math

print(math.asin(1))

print(math.acos(0))

print(math.atan(1))

Output:

1.5707963267948966

1.5707963267948966

0.7853981633974483

1. sinh(x) Function

sinh(x) returns the “hyperbolic sine of the angle” of the input.

2. cosh(x) Function

The cosh(x) returns the “hyperbolic cosine of the angle” of the input.

3. tanh(x) Function

tanh(x) returns the “hyperbolic tangent of the angle” of the input.

Example:

import cmath

x = 1.0

y = 1.0

z = complex(x,y)

print (cmath.sinh(z))

print (cmath.cosh(z)) 

print (cmath.tanh(z))

Output:

(0.6349639147847361+1.2984575814159773j)

(0.8337300251311491+0.9888977057628651j)

(1.0839233273386946+0.2717525853195118j)

Note: cmath module comprises a set of methods and constants. Used when the user uses complex numbers for mathematical operations.

1. asinh(x) Function

asinh(x) returns the “inverse of hyperbolic sine of the angle” of the number.

2. acosh(x) Function

acosh(x) returns the “inverse of hyperbolic cosine of the angle” of the number.

3. atanh(x) Function

atanh(x) returns the “inverse of the hyperbolic tangent of the angle” of the number.

Example:

import cmath

a = 1.0

b = 1.0

c = complex(a,b)

print (cmath.asinh(c))

print (cmath.acosh(c)) 

print (cmath.atanh(c))

Output:

(1.0612750619050357+0.6662394324925153j)

(1.0612750619050357+0.9045568943023813j)

(0.40235947810852507+1.0172219678978514j)

1. atan2(y, x) Function

This function means atan2(y/x). Y and X are both numeric values. This function returns a value that falls between -pi and pi.

Example:

print(math.atan2(1.2,1.3))

Output:

0.7454194762741583

2. hypot(x, y) Function

in-built function in python in math module that returns Euclidean norm,

Python Trigonometric Functions

Syntax :

hypot(x, y)

Parameters :

 x and y are numeric values

Returns :

Returns a float value having Euclidean norm, sqrt(x*x + y*y).

Error :

When two  or more arguments are

passed, it returns a TypeError.

Note: When values will be compared to numeric values .decimal places might be different and can be ignored.

Can we get errors?

Yes, you can get errors and there are two kinds of errors.

  1. TypeError: when a non-numeric value is passed to the trigonometric methods.
  2. ValueError: when an invalid value is passed to trigonometric methods.

Conclusion

In this article, we learned about how we can use various trigonometric methods in python by importing mat module by using “Import math”. Just remember not to pass invalid parameters to trigonometric methods. Pass values in degrees to convert in radians and vice-versa.



ADVERTISEMENT
ADVERTISEMENT