![]() |
VOOZH | about |
Sin(x) is also known as Sine. It is a trigonometric function of an angle. In a right-angled triangle, the ratio of the length of the perpendicular to the length of the hypotenuse is known as the sine of an angle.
sin θ = perpendicular / hypotenuse
The values of sine of some of the common angles are given below,
This article focuses upon how we can calculate the sine of an angle by in C#.
We can calculate the sine of an angle by using the inbuilt sin() method. This method is defined under the Math class and is a part of the system namespace. Math class is quite useful as it provides constants and some of the static methods for trigonometric, logarithmic, etc.
Syntax:
public static double Sin (double angle);
Parameter:
Return type:
Example 1:
The value of sin(0) = 0 The value of sin(45) = 0.707106781186547 The value of sin(90) = 1 The value of sin(135) = 0.707106781186548
Example 2:
Output
Sine of angle1: NaN Sine of angle2: NaN Sine of angle3: NaN
Time complexity: O(n), where n is the number of terms calculated for the Maclaurin's series approximation of sin(x).
Space complexity: O(1).
We can calculate the value of sine of an angle using Maclaurin expansion. So the Maclaurin series expansion for sin(x) is:
sin(x) = x - x3 / 3! + x5 / 5! - x7 / 7! + ....
Follow the steps given below to find the value of sin(x):
This formula can compute the value of sine for all real values of x.
Example:
The value of sin(45) = 0.707106781186547 The value of sin(90) = 1 The value of sin(135) = 0.707106781186548 The value of sin(180) = 2.34898825287367E-16
Time complexity: O(n). //n is the number of terms passed as input.
Space complexity: O(1).