Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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

I don't know what is actually used by any calculators, but a lookup table with linear (or higher order if you want) interpolation should be simple and accurate enough for 3 places of accuracy, or more with a denser table. You would only need a table for one quarter-cycle and could use it for all sine and cosine calculations with appropriate transformations. If you have enough power and precision, you could try iterating a taylor series or something, but rounding errors will accumulate on you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top