Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What kind of algorithm do calculators follow to find values of sine?

If someone gives me an angle of say, 38 degrees, how will I find out the value of the sine function for it value without using actually making a right triangle with 38 degrees and measuring the sides? I know I can use some trigonometric identities to close in on the values but that would be laborious.

I am sure that the algorithms used in calculators and computers won't resort to doing that. Like if I need to find pi, I will use an algorithm like this :

A very efficient algorithm used to compute the value of pi

instead of getting a compass and a ruler and drawing circles.

However, I cannot find any such algorithm for a sine function.

Can someone please help me with this?

like image 711
Aayush Mahajan Avatar asked Jan 04 '14 18:01

Aayush Mahajan


People also ask

What is sine cosine algorithm 2?

2. Sine-Cosine Algorithm The SCA algorithm was proposed by Seyedali Mirjalili in 2016. It is a population-based metaheuristic algorithm applied to optimization problems.

How do you find the sine of a given angle?

A calculator or computer program is not reading off of a list, but is using an algorithm that gives an approximate value for the sine of a given angle. There are several such algorithms that only use the four basic operations (+, −, ×, /) to find the sine, cosine, or tangent of a given angle.

What is sine-cosine algorithm (SCA)?

In this tutorial, we take a look at a very recent algorithm: the sine-cosine algorithm or SCA. It is an optimization procedure that belongs to the family of population-based metaheuristic techniques. Within these, it belongs to the math-based algorithms. 2. Sine-Cosine Algorithm The SCA algorithm was proposed by Seyedali Mirjalili in 2016.

How do calculators calculate trigonometry?

In fact, a calculator uses some kind of algorithm based on the basic operations not only to calculate trigonometric values, but also square roots, values of hyperbolic functions and others. The branch of mathematics called numerical methods studies and develops these algorithms.


2 Answers

One of the most common algorithms for this is to take first few terms of Taylor series for sine.

sin x = x - x3/3! + x5/5! - x7/7! + ...,

The more terms you take the better approximation you get. X is in radians here, but you can get radians from degrees quite easily. And then, as you see, only basic operations: +, -, *, / can be used to calculate the sine.

In machines with floating-point coprocessor chips CORDIC algorithm (with a few other modules) is used, as it also can be implemented in hardware.

like image 168
3yakuya Avatar answered Nov 09 '22 23:11

3yakuya


Improving John's answer:

Create a table of sin(x) for x in different radians from 0 to pi/2.

You can use interpolation as follows: sin(x+dx) = sin(x) + dx*cos(x)

cos(x) = sin(pi/2-x).

Similarly, cos(x+dx) = cos(x) - dx*sin(x).

like image 43
ElKamina Avatar answered Nov 09 '22 23:11

ElKamina