Sunday, March 13, 2016

Extending the Range of tan(θ) and atan(t)

The tangent and inverse tangent function in Mathcad only work as one would like them to for multiples of θ=π/2. If one computes θ'=atan[tan(θ)] one will see that the difference Δθ=θ'-θ=±kπ/2 for some integer k.

One has to keep track of which quadrant θ is in and redefine both functions in order to get θ'=θ. The simplest solution that I could find is shown below.

A recheck shows that everything works out as one would want.

This this should work for any value of θ since the new definitions avoid values close to where the inverse tangent function is discontinuous, i.e., θ=±π/2.

Edit (Mar 14): I did a little more testing and found a missing case in the earlier program so I replaced the image formerly posted with programs containing the newer version. There was a problem with just θ=-π/2 for the extended range. Bugs like that can be very difficult to find.

No comments: