Greetings,

Before I begin I would like to apologies for the jerkiness of my gif. This is my first attempt at making one so I was more interested in learning how to make the gif then in making it rotate smoothly. I actually did the rotation by hand because I was being lazy and didn't want to take the time to run it through a rotation matrix about the z-axis. For those of you who drink coffee you will recognize this as a molecule of caffeine.

Over the years I've learned a few tricks about using trig functions that I thought I would share with anyone who might be interested. I did a quick search on this site and didn't really see where anyone has discussed this subject.

The ATAN2() function
--------------------
Your calculator has the three trigonometric functions sine, cosine and tangent on it's keypad. It also has the inverse functions arc-sine, arc-cosine and arc-tangent; which are incorrectly labeled on the keypad as recipricals (one of those little things in life that I find annoying, so don't get me started).

Anyone who uses trig functions regularly knows that the arc-sine and arc-tangent will return a result the lies between -90 deg and +90 deg, while the arc-cosine function returns a result that is between 0 deg and +180 deg. This means that in some cases the result obtained will not be in the correct quadrant. Normally, you are required to put in some testing procedures into your program to determine which quadrant your result should be in and make the appropriate correction.

For an example, in astronomy there is a simple equation that is used to calculate the position of the Sun called the right ascension. It can be calculate using this equation:
tan(α) = (cos(ε) sin(L))/cos(L)
So if you plug in the values of ε = 23.43949 deg and L = 220.24429 deg you get
tan(α) = cos(23.42949) sin(220.24429)/cos(220.24429)
tan(α) = 1.0645742
Now taking the arc-tangent gives: α = atan(1.0645742) = 46.79147 deg.
The problem, of coarse, is that this is the wrong answer. The correct answer is α = 226.79147 deg.

The way to get around this problem is to use the atan2() (arc-tangent 2) function found in most computer languages and spreadsheet programs. There is one rule to using the atan2() function and that is that your equation must be in the form tan(θ) = x/y. You do not perform the division x/y, rather you separate both values and enter them into the atan2() function. So for the above problem you would separate the numerator and denominator like this:
x = cos(23.42949) sin(220.24429) = -0.6949915
and y = cos(220.24429) = -0.6528353.
Now you would plug these numbers into the atan2() function:
atan2(-0.6949915,-0.6528353) = 226.79147 deg
So now you will get the answer in the correct quadrant and you didn't have to do any testing. One thing to keep in mind. Over the years I've come across implementations where the atan2() function was defined as atan2(x,y) and as atan2(y,x). So be careful.

So all is paradise throughout the land and your fellow programmers carry you around the room as the greatest programmer in the world. There is just one little problem. No matter how hard you look, you will not be able to find the atan2() function on your TI calculator.

So what's the deal? Why did TI leave out that function? Well, actually TI didn't forget it. It is actually there, TI just hid it. It is one of those things that you will never find unless you know what you are looking for. And so it is with the atan2() function. It is located in the ANGLE menu as R►Pθ(. This is actually the Rectangular to Polar conversion function, but it is also the atan2 function.

So give it a try like this
R►Pθ(-0.6528353,-0.6949915) = -133.2085345 + 360
= 226.7914655 deg.
Note that this is in the form atan2(y,x).
On my calculator I've created a TI-BASIC program called ATAN2 to do this for me.

SIN and COS functions
---------------------
From time to time you will need to solve functions that look like this:
h = e sin(p - p₀)
k = e cos(p - p₀) - e₀
Solve for p and e, where h, k, p₀ and e₀ are known. Since both p and e are unknowns most people would immediately rearrange one of these equations for e and substitute it into the other and solve for p. Then go back and solve for e.

You will, of coarse, have the problem stated above when dealing with arc-sine and arc-cosine functions.

There is a much more elegant way of solving this problem and get the result in the proper quadrant. Here is what you do.

The first thing to do is rearrange the second equation to get
k + e₀ = cos(p - p₀).
Next, you divide one equation by the other like this:
h/(k + e₀) = (e sin(p - p₀)/(e cos(p - p₀)
This immediately reduces to:
h/(k + e₀) = sin(p - p₀)/cos(p - p₀).
Now, it is time for you to dust off a trigonometry book. The tangent function is defined as:
tan(θ) = sin(θ)/cos(θ).
This helps us because our equation becomes:
h/(k + e₀) = tan(p - p₀)
Notice that I purposely divided the two equations so I would get sin/cos.
Now, you solve for p using:

atan(h/(k + e₀)) = p - p₀

Look at this equation carefully. It should look familiar to you. Whenever you have an arc-tangent equation in the form tan(θ) = x/y you can use the atan2() function to get the result in the correct quadrant. And so, that is how you solve this equation
p = atan2(h/(k + e₀) - p₀)
If you keep your eye on the look out you will find that you can use this relationship all the time.

Here is another example. These equations are used to rotate about an axis.

cos(δ) cos(α - z) = cos(θ)cos(δ₀)cos(α₀+L) - sin(θ)sin(δ)
cos(δ) sin(α - z) = cos(δ₀)sin(α₀+L)
sin(δ) = sin(θ)cos(δ₀)cos(α₀+L) + cos(θ)sin(δ₀)

It might not appear obvious but you solve this equation exactly the same way we solved the previous one. You solve the first two equations to get tan(α - z) and then take the atan2().

I hope someone might find this information useful someday.
Uh, when you look at the functions sin^-1, cos^-1, tan^-1 that -1 doesn't mean reciprocal, it means inverse function. It's much like the matrix inverse in y = A . x becomes x = A^-1 . y . It's only when talking about real numbers that the inverse and the reciprocal co-incide, 1/2 = 2^-1 because the inverse of 2 is 1/2.
Yes, they are aware of this.

Quote:
which are incorrectly labeled on the keypad as recipricals (one of those little things in life that I find annoying, so don't get me started).
Greetings,

As I said this is just one of my annoyances in life. I do in fact know that it means the inverse trig function.

You could write the square of the sine of θ as sinθ² but often you see it written as sin²θ, like in Pythagorean trig identity sin²θ + cos²θ = 1. The problem with using this notation is that it means the square of the sine of θ but it looks like you are taking sin (sin θ). This becomes even more confusing if someone uses this notation to write the reciprocal as sin⁻¹θ instead of writing it as sinθ⁻¹.

Because I believe math should always be clear about what you mean I prefer to always write out arc-sine to mean to the inverse trig function. But obviously not everyone agrees with me.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement