Python sin to degrees

Python sin – Find Sine of Number in Radians Using math.sin()

To find the sine of a number (in radians), we can use the Python sin() function from the math module.

In Python, we can easily use trigonometric functions with the Python math module. The Python math module allows us to perform trigonometry easily.

With the Python math module, we can find the sine of a number easily.

To find the sine of a number, in radians, we use the math sin() function.

Below is the Python syntax to find the sine of a number.

The input to the sin() function must be a numeric value. The return value will be a numeric value between -1 and 1.

import math print(math.sin(math.pi/3)) print(math.sin(0)) print(math.sin(math.pi/2)) #Output: 0.8660254037844386 0.0 1.0

Converting Degrees to Radians for Input into sin()

The sin() function takes a number in radians as input. If your data is in degrees, you will need to convert the values to radians.

The Python math module has a useful function to convert degrees to radians, the math radians() function.

If we have a value in degrees, we can use radians() to convert the value to radians and then pass it to the sin() function.

import math print(math.sin(math.radians(60))) print(math.sin(0)) print(math.sin(math.radians(90))) #Output: 0.8660254037844386 0.0 1.0

Finding the Inverse Sine of a Number in Python

The Python math module also provides us trigonometric functions to find the inverses of the common trigonometric functions. The asin() function allows us to find the inverse of the sine of a number.

Читайте также:  Python dataframe name columns

Below, we show that if we pass a number to sin() and then call the Python asin() function, we get back the same number.

import math print(math.asin(math.sin(math.pi/3))) print(math.pi/3) #Output: 1.0471975511965976 1.0471975511965976

Finding the Cosecant of a Number in Python

To find the cosecant of a number, we can divide 1 by the sine of the number.

We can find the cosecant of a number easily with the Python sin() function. You can see how to find the cosecant of a number in the following Python code.

import math print(1/math.sin(math.pi/3)) #Output: 1.1547005383792517

Hopefully this article has been beneficial for you to understand how to use the math sin() function in Python to find the sine of a number.

  • 1. Python turtle dot() – Draw Dot on Turtle Screen
  • 2. Remove Character from String in Python by Index
  • 3. Divide Each Element in List by Scalar Value with Python
  • 4. How to Check if Variable Exists in Python
  • 5. Remove Decimal from Float in Python
  • 6. Sort by Two Keys in Python
  • 7. Convert String to Integer with int() in Python
  • 8. Convert pandas Series to Dictionary in Python
  • 9. How to Find the Longest String in List in Python
  • 10. Remove Empty Strings from List in Python

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Источник

Python math.sin() Method

Note: To find the sine of degrees, it must first be converted into radians with the math.radians() method (see example below).

Syntax

Parameter Values

Parameter Description
x Required. The number to find the sine of. If the value is not a number, it returns a TypeError
Читайте также:  Задачи на основе python

Technical Details

More Examples

Example

Find the sine of different degrees:

# Import math Library
import math

# Return the sine value of 30 degrees
print(math.sin(math.radians(30)))

# Return the sine value of 90 degrees
print(math.sin(math.radians(90)))

Unlock Full Access 50% off

COLOR PICKER

colorpicker

Join our Bootcamp!

Report Error

If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:

Thank You For Helping Us!

Your message has been sent to W3Schools.

Top Tutorials
Top References
Top Examples
Get Certified

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Источник

Python math.sin() Method

Python provides several built-in functionalities for each purpose. These functions can be utilized through the different modules and libraries that become handy sometimes for each purpose. Likewise, the “math” module is one that contains multiple mathematical operations, such as the “sin()” method assists in finding sine values in radian form.

This write-up will describe:

What is “math.sin()” Method in Python?

In Python, multiple built-in methods are available for performing different operations, such as “sin()”. More specifically, “math.sign” is a built-in math function that provides the functionality of finding the sine values of the parameter passed to it in radian form. To use this function, the Pythons “math” module can be imported into the particular program.

The syntax of the “sin()” method is:

Here, the math.sin() method outputs the sine value of “x”.

How to Use the “math.sin()” Method for Finding Values in Python?

The “Math.sin()” method can be used to get the sine value of the input. To understand the working of this particular function, let’s try out the following examples.

Читайте также:  Дата от 1970 php

Example 1: Calculate the “sin()” Value of the Integer Number in Python

To calculate the sine value of any integer number, first import the “math” library:

Call the “sin()” method with argument through the math.sin()“ statement inside the “print()” function

As you can see, the sine value of the provided integer number is displayed below:

Example 2: Calculate the “sin()” Value of the Float Number in Python

If a user wants to get the sin or sine value of the floating number, first, initialize the “float_value” floating variable with desired floating value and passed to it:

Use the “print()” statement with “sin()” method and pass a floating variable to it:

Example 3: Calculate the “sin()” Value of the Degree

As we know the “sin()” method returns the radian value. However, the calculator returns the degrees. The Python built-in “math” module has the “radians()” function to change the radian value of the “sin()” function into the degree.

To change the radian value into the degree, call the “radians()” method with parameters and pass as to the “sin()” function. Then, print the degree value using the “print” statement:

The degree of the provided value has been displayed as output:

We have elaborated on the Python math.sin() method with examples.

Conclusion

The “sin()” method is the built-in function of Python. To use this function, the “math” module can be imported into the particular program that provides the functionality of finding the sine values of the parameter passed to it in radian form. This write-up discussed the usage of Python math.sin() method with examples.

About the author

Maria Naz

I hold a master’s degree in computer science. I am passionate about my work, exploring new technologies, learning programming languages, and I love to share my knowledge with the world.

Источник

Оцените статью