Calculator Magic #4 Trigonometry Functions |

The ABC's of It

Prerequisite:
Introduction to Programming a Four-Function Calculator

Suggested Reading: The Black Box Challenge

If you don't have your Trigonometry tables handy, not all is lost. You can accomplish everything you need with your simple calculator, with sufficient accuracy to please anyone. Taylor series and Maclaurin series lend themselves to easy programming in factored form, so those are what we will use.

Evaluating angles on a 360° scale is an arbitrary decision, based upon that
number's great factorability. Trig tables accommodate specifications in
degrees, because that's how most humans relate to them. Yet the principles
of trigonometry are based upon **pi**, not 360. For our purposes,
any angle specified in degrees must first be converted to radians, as follows:

That decimal value is irrational, so a 7-digit approximation is the best that we can do with a calculator.

SINE

The power series for sine is:

That structure is inconvenient, but the first first five terms of the series can be factored thusly:

This will be plenty accurate enough for most any application. Let's try a problem: sin(32°):

32 × .0174533 M+ | x (radians) to memory |

× = ÷ 72 - 1 | |

× MR × MR ÷ 42 + 1 | |

× MR × MR ÷ 20 - 1 | |

× MR × MR ÷ 6 + 1 | |

× MR MC = | {.5299194} |

That's all there is to it. x was stored in memory, which was cleared in the last step to prepare for the next calculation. The result is accurate to six places.

One can opt for a shortcut formula, using only the first three factors from the series:

32 × .0174533 M+ | |

× = ÷ 20 - 1 | |

× MR × MR ÷ 6 + 1 | |

× MR MC = | {.5299228} |

This result still is accurate to five places! Powerful stuff.

COSINE

The power series is:

The first five terms factor to:

Let's do a problem: cos(17.4°). The program structure is similar to the first one:

17.4 × .0174533 M+ | |

× = ÷ 56 - 1 | |

× MR × MR ÷ 30 + 1 | |

× MR × MR ÷ 12 - 1 | |

× MR × MR ÷ 2 + 1 | |

× MR MC = | {.9542404} |

Once again — 6-decimal accuracy. The correct value is {.9542403}. How well does a 3-factor shortcut fare this time?

17.4 × .0174533 M+ | |

× = ÷ 12 - 1 | |

× MR × MR ÷ 2 + 1 | |

× MR MC = | {.9542414} |

Same story — 5 good digits. This stuff is easy.

TANGENT

There are options here. You could calculate sin x and divide it by cos x, or else try a new series:

The fifth term of the series does not lend itself to these factoring methods; so we will use four terms only:

Let's try tan(23°):

23 × .0174533 M+ | |

× = × 17 ÷ 42 + 1 | |

× MR × MR × 2 ÷ 5 + 1 | |

× MR × MR ÷ 3 + 1 | |

× MR MC = | {.4244686} |

The correct value is {.4244744}. Not bad.

A value for secant, cosecant, or cotangent can easily be derived by taking the reciprocal of its corresponding function.

The programs for the inverse functions can be somewhat more ~~complicated —~~
particularly that for Arccosine. Each calculated value is converted from radians
back to degrees at the end, by dividing by pi/180.

ARCSINE

Here is just the factored series:

In this case, x is the sine of some angle. Extracting the arcsine yields the angle itself.

The structure of the equation is the same as for a sine, with the addition of the odd perfect squares in the numerators. That adds a few keystrokes to the program code. Since we already have calculated the sine of 32°, let's try taking arcsin(sin(32)):

.5299195 M+ | |

× = × 49 ÷ 72 + 1 | |

× MR × MR × 25 ÷ 42 + 1 | |

× MR × MR × 9 ÷ 20 + 1 | |

× MR × MR ÷ 6 + 1 | |

× MR MC = | {.5584789} |

That's the angle, in radians. To convert back to degrees, we continue with:

÷ .0174533 = | {31.99847} |

That's only 4-digit accuracy, because the arcsine series resolves relatively slowly. It's the best we can do without incorporating more factors.

ARCCOSINE

It would be convenient to utilize this relationship:

This series fails, however, unless x is quite small. Another identity reduces the size of the number for our program:

We can use the [sqrt] key to help us solve arccos(.9542403):

.9542403 × = M+ | |

1 - MR MC = | value of the radical |

SQRT M+ | {.2990409} |

× = × 49 ÷ 72 + 1 | |

× MR × MR × 25 ÷ 42 + 1 | |

× MR × MR × 9 ÷ 20 + 1 | |

× MR × MR ÷ 6 + 1 | |

× MR MC M+ | {.3036873} = radians |

3.14159 ÷ 2 - MR MC = | {17.399993} |

We were expecting 17.4°, and we got it!

ARCTANGENT

This factors to:

Let's try arctan(.42447):

.42447 M+ | |

× = × 7 ÷ 9 - 1 | |

× MR × MR × 5 ÷ 7 + 1 | |

× MR × MR × 3 ÷ 5 - 1 | |

× MR × MR ÷ 3 + 1 | |

× MR MC | |

÷ .0174533 = | {23.00012} |

That's 5-digit accuracy — as much as we started with. Here is the 3-factor shortcut:

.42447 M+ | |

× = × 3 ÷ 5 - 1 | |

× MR × MR ÷ 3 + 1 | |

× MR MC | |

÷ .0174533 = | {23.017595} |

That's three good digits — plenty adequate for a minimal routine.

The power series for the hyperbolic functions are more complicated, with
each having a negative exponent. They could be programmed, ~~though —~~
perhaps another time.