Javascript required
Skip to content Skip to sidebar Skip to footer

Find the Solutions to Sin2x-sinx 0

C# Program to Find the Value of Sin(x)

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 comman angles are given below,

  1. sin 0° = 0
  2. sin 30° = 1 / 2
  3. sin 45° = 1 / √2
  4. sin 60° = √3 / 2
  5. sin 90° = 1

This article focuses upon how we can calculate the sine of an angle by in C#.

Method 1

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:

  • angle: A double value (angle in radian)

Return type:

  • double: If "angle" is double
  • NaN: If "angle" is equal to NaN, NegativeInfinity, or PositiveInfinity

Example 1:

C#

using System.IO;

using System;

class GFG{

static void Main()

{

double angleInDegree1 = 0;

double angleInRadian1 = (angleInDegree1 * (Math.PI)) / 180;

Console.WriteLine( "The value of sin({0}) = {1} " ,

angleInDegree1, Math.Sin(angleInRadian1));

double angleInDegree2 = 45;

double angleInRadian2 = (angleInDegree2 * (Math.PI)) / 180;

Console.WriteLine( "The value of sin({0}) = {1} " ,

angleInDegree2, Math.Sin(angleInRadian2));

double angleInDegree3 = 90;

double angleInRadian3 = (angleInDegree3 * (Math.PI)) / 180;

Console.WriteLine( "The value of sin({0}) = {1} " ,

angleInDegree3, Math.Sin(angleInRadian3));

double angleInDegree4 = 135;

double angleInRadian4 = (angleInDegree4 * (Math.PI)) / 180;

Console.WriteLine( "The value of sin({0}) = {1} " ,

angleInDegree4, Math.Sin(angleInRadian4));

}

}

Output

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:

C#

using System;

class GFG{

static public void Main()

{

double angle1 = Double.NegativeInfinity;

double angle2 = Double.PositiveInfinity;

double angle3 = Double.NaN;

Console.WriteLine( "The value of sin({0}) = {1} " ,

angle1, Math.Sin(angle1));

Console.WriteLine( "The value of sin({0}) = {1} " ,

angle2, Math.Sin(angle2));

Console.WriteLine( "The value of sin({0}) = {1} " ,

angle3, Math.Sin(angle3));

}

}

Output

Sine of angle1: NaN Sine of angle2: NaN Sine of angle3: NaN

Method 2

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):

  1. Initialize a variable angleInDegree that stores the angle (in degree) to be calculated.
  2. Initialize another variable terms that stores the number of terms for which we can approximate the value of sin(x).
  3. Declare a global function findSinx.
  4. Declare a variable current. It stores the angle in radians.
  5. Initialize a variable answer with current. It will store our final answer.
  6. Initialize another variable temp with current.
  7. Iterate from i = 1 to i = terms. At each step update temp as temp as ((-temp) * current * current) / ((2 * i) * (2 * i + 1)) and answer as answer + temp.
  8. Eventually, return the answer from findSinX function.
  9. Print the answer.

This formula can compute the value of sine for all real values of x.

Example:

C#

using System;

class GFG{

static double findSinX( int angleInDegree, int terms)

{

double current = Math.PI * angleInDegree / 180f;

double answer = current;

double temp = current;

for ( int i = 1; i <= terms; i++)

{

temp = ((-temp) * current * current) /

((2 * i) * (2 * i + 1));

answer = answer + temp;

}

return answer;

}

static public void Main()

{

int angleInDegree1 = 45;

int terms1 = 10;

double answer1 = findSinX(angleInDegree1, terms1);

Console.WriteLine( "The value of sin({0}) = {1}" ,

angleInDegree1, answer1);

int angleInDegree2 = 90;

int terms2 = 20;

double result2 = findSinX(angleInDegree2, terms2);

Console.WriteLine( "The value of sin({0}) = {1}" ,

angleInDegree2, result2);

int angleInDegree3 = 135;

int terms3 = 30;

double result3 = findSinX(angleInDegree3, terms3);

Console.WriteLine( "The value of sin({0}) = {1}" ,

angleInDegree3, result3);

int angleInDegree4 = 180;

int terms4 = 40;

double result4 = findSinX(angleInDegree4, terms4);

Console.WriteLine( "The value of sin({0}) = {1}" ,

angleInDegree4, result4);

}

}

Output

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

Find the Solutions to Sin2x-sinx 0

Source: https://www.geeksforgeeks.org/c-sharp-program-to-find-the-value-of-sinx/?ref=rp