Table of Contents
Advanced/Extended Trigonometry Functions
Arguably, most Trigonometry requirements are served by the three staples of Sine, Cosine and Tangent almost exclusively. There are however, many more functions which can be required. Their use is sufficiently rare though, that native functions are probably a waste of firmware space and development when they can be synthesized from the other mathematical primitives in a language.
The following code is all written in MMBasic but that language is a good “pseudo-code” allowing easy transcribing to just about any other. A good discussion on all trig functions and how/why to use them can be found here:https://en.wikipedia.org/wiki/Trigonometric_functions
The below functions have been tested against Wolfram Alpha for correct function. Most are fine but three may be considered a “work in progress”. This status is clearly indicated against each function. Please feel free to correct those that currently do not work as expected.
Secant, CoSecant and CoTangent:
Function Sec(x As Float) As Float'OK Sec=1/Cos(x) End Function Function Cosec(x As Float) As Float'OK Cosec=1/Sin(x) End Function Function Cot(x As Float) As Float'OK Cot=1/Tan(x) End Function
Hyperbolic function counter-parts:
Function Sinh(x As Float) As Float'OK Sinh=(Exp(x)-Exp(-x))/2 End Function Function Cosh(x As Float) As Float'OK Cosh=(Exp(x)+Exp(-x))/2 End Function Function Tanh(x As Float) As Float'OK Tanh=(Exp(-x)/Exp(x)+Exp(-x))*2+1 End Function Function Sech(x As Float) As Float'OK Sech=2/(Exp(x)+Exp(-x)) End Function Function Cosech(x As Float) As Float'OK Cosech=2/(Exp(x)-Exp(-x)) End Function Function Coth(x As Float) As Float'OK Coth=Exp(-x)/(Exp(x)-Exp(-x))*2+1 End Function
The Inverse counterparts
Function Sin_1(x As Float) As Float'OK Sin_1=Atn(x/Sqr(-x*x+1)) End Function Function Cos_1(x As Float) As Float'OK Cos_1=-Atn(x/Sqr(-x*x+1))+Pi/2 End Function Function Sec_1(x As Float) As Float Sec_1=Acos(1/x)'formula from openai.com, still not convinced since arcsec(0.5)=1.31696 on WA, but errors on Acos End Function Function Cosec_1(x As Float) As Float' x>1, OK Cosec_1=Atn(x/Sqr(x*x-1))+(Sgn(x)-1)*Pi/2 End Function Function Cot_1(x As Float) As Float'formula from openai.com Cot_1=Atn(1 / x) End Function Function Sinh_1(x As Float) As Float' OK Sinh_1=Log(x+Sqr(x*x+1)) End Function Function Cosh_1(x As Float) As Float' OK Cosh_1=Log(x+Sqr(x*x-1)) End Function Function Tanh_1(x As Float) As Float' OK Tanh_1=Log((1+x)/(1-x))/2 End Function Function Sech_1(x As Float) As Float Sech_1=Log((1+Sqr(1-x*x))/x)'formula from openai.com End Function Function Cosech_1(x As Float) As Float' OK Cosech_1=Log((Sgn(x)*Sqr(x*x+1)+1)/x) End Function Function Coth_1(x As Float) As Float' OK Coth_1=Log((x+1)/(x-1))/2 End Function