Question

I'm trying to implement inverse trigonometric functions in a C# application. Obviously I'm not talking about simple inverse sin, cos and tan seeing as those are all provided by the Math class. What I'm looking for is the inverses for sec, cosec and cotan:

Func<double,double> secant = (d => (1 / Math.Cos(d)));
Func<double,double> cosecant = (d => (1 / Math.Sin(d)));
Func<double,double> cotangent = (d => (Math.Cos(d) / Math.Sin(d)));

Now my problem is that I want to implement the inverses of each of these but I can't seem to find a simple definition of the appropriate inverses - arcsec, arccsc and arccot - which I can turn into C# code.

So my question is can you either (a) point me in the direction of a good resource or (b) show me some example code for this?

Was it helpful?

Solution

Surely you jest:

asec(x) = acos(1 / x)
acsc(x) = asin(1 / x)
acot(x) = atan(1 / x)

:-P

OTHER TIPS

For inverse cotangent, using atan(1 / x) will not always work. For example, I needed to do a fairly complicated equation:

y = 0.25 * arccot((2.5x / 100000) - 2.1) + 0.26

When implementing the atan(1 / x) solution, it results in a break when (2.5x / 100000) - 2.1 is zero, and all the values to the left of that point are below the correct values by pi / 4.

Instead, using an implementation as such provides the exact answers for all points needed:

y = 0.25 * ((pi / 2) - atan((2.5x / 100000) -2.1) + 0.26

I would suggest going to desmos.com/calculator or some other graphing utility and graphing the actual arccot function, then comparing various implementations to make sure you are getting what you want for all values.

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