How to use the sin method in Julia

Overview

The sin() method calculates the sine value of x , where xis in radians.

Syntax

sin(x)
Julia's sin function syntax

Parameter

This method takes the parameter x, which represents the radian value for which the sine value is to be found.

Return value

This method returns the sine value of the argument.

Code

The code below demonstrates the use of the sin method:

## find sin of radian
degree = 0
radian = deg2rad(degree)
println( "sin($(radian)) => $(sin(radian))")
## find sin of 10
degree = 10
radian = deg2rad(degree)
println( "sin($(radian)) => $(sin(radian))")

Explanation

Line 2: We create a new variable degree and assign 0 as a value to it.

Line 3: We use the deg2rad method with the degree variable as an argument. This method converts the degree to radians. The radian value of 0 degrees is 0.0.

Line 4: We use the sin method with the variable radian as an argument. This method calculates the sine value of the radian. In our case, the sine value of radian is 0.0.

Line 7: We assign 10 as the value for the degree variable.

Line 8: We use the deg2rad method with the degree variable as an argument. This method converts the degree to radians. The radian value of 10 degrees is 0.17453292519943295.

Line 9: We use the sin method with the variable radian as an argument. This method calculates the sine value of the radian. In our case, the sine value of radian is 0.17364817766693033.

Free Resources