×

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.


Related Topics

Python delattr() function

Python delattr() function The delattr() function in Python is used to delete the named attribute from the object, with the prior permission of the object. Syntax delattr(object, name) Parameter object : This parameter represents the object from which...

1 minute read.

Python program to print calendar

Python program to print the calendar This article will explain how to print the calendar of month and year using Python's calendar module. It's a straightforward thing in Python by importing...

1 minute read.

Python List insert() method

Python List insert() method The list.insert () method in Python inserts an item at the specified position. Syntax list.insert(i, x) Parameter i: This parameter represents a number specifying the position to insert the given value. x: This parameter signifies...

1 minute read.

Difference between For Loop and While Loop in Python

What is the “For” loop? The “For” Loop is a commonly used control structure in programming that allows us to repeat a set of actions multiple times. The “For” loop is...

3 minutes read.

Python abs() function

Python abs() function The abs() function returns the absolute value of a number. Syntax abs(x) Parameter x: The parameter ‘x’ can be an integer value, a floating point number or a complex number. Return This function returns...

1 minute read.

Python Rest API

In this tutorial, we will understand the meaning of API and REST API. We will understand the working of REST API. We will then realize the boundaries of architecture defined...

4 minutes read.

Python Queue

Python Queue There are various day to day activities where we find ourselves engaged with queues. Whether it is waiting in toll tax lane or standing on the billing counter for...

7 minutes read.

Python Set isdisjoint() method

Python Set isdisjoint() method The set.isdisjoint() method in Python returns a boolean value True if two sets are disjoint sets ( i.e. none of the elements are present in both sets), otherwise it returns...

1 minute read.

Python for Data Analysis

Data analysis uses various techniques to read, illustrate, manipulate and evaluate a particular data. You can have access to the data and keep the data updated regularly. You can append...

4 minutes read.

Python IDE names

Python is one of the most renowned programming languages. It has different execution conditions and a great many compilers to execute the python programs, e.g., PyCharm, PyDev, Jupyter Notebook, Visual...

6 minutes read.

Python Syntax Error Invalid Syntax

Python is renowned for its simple and direct syntax. However, we might come across some things that Python doesn't allow if we are learning Python for the very first time or if...

14 minutes read.

How to Define a Function in Python?

What is a Function? In programming, a piece of code that executes a specific task or a group of related operations is known as a function. What does Python Functions Do? If you...

6 minutes read.

Python whois

What is whois? Whois is a protocol used to identify the owner of the registered domain name. It is a querying database that is used to record the registered users. WHOIS is...

4 minutes read.

Python Data Types

Python Data Types: The variable in Python is used to store values, and they can hold different values. Each variable in Python has its own data-type. Since Python is a...

13 minutes read.

Conditional Statements in python

In this article, we will learn about conditional statements and how to apply conditional statements in Python. A decision-making statement is another name for a conditional statement. Decision-making is an important...

5 minutes read.

OS Module in Python

What is a module? The Modules are the kind of files that contains python statements and definitions. The module is known by the name of the file followed by the suffix...

8 minutes read.

Gaussian elimination in python

Linear and polynomial equations are used in almost all fields of numerical simulation. However, its most common use in engineering is in the area of linear system analysis. The broader...

3 minutes read.

Python Dictionary clear() method

Python Dictionary clear() method The dictionary.clear() method in Python removes all the elements from a dictionary. Syntax dictionary.clear() Parameter NA Return None Example 1 # Python program explaining # the dictionary.clear() method # initialising the dictionary fruits =...

1 minute read.

How to assign values to variables in Python and other languages?

Python makes it simple to construct variables. The value to be stored in the variable should then be written after a suitable name for the variable and the equality sign....

3 minutes read.

Best app for python

What is python? Python is a prevalent, general-purpose, and high-level programming language. Python Programming Language is appropriate for experienced programmers and also for beginners. Python programming language is being utilized by...

19 minutes read.