Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 09:10 01 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Extended Trig Functions

Author Message
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 2170
Posted: 09:59am 23 Apr 2022
Copy link to clipboard 
Print this post

Found this in the appendices of some old reference books.

A bit niche but you never now when you might need a Hyperbolic Cosecant. Just stash it away and if you never need it, be happy  



and because I am a sad case, here is the MMBasic for the first group, all tested against Wolfram Alpha. I was going to do the inverse functions too but there is something I need to tweak to get the parsing of the arguments right - it's probably too vague to matter; would anyone ever use them?

Function Sec(x As Float) As Float
Sec=1/Cos(x)
End Function

Function Cosec(x As Float) As Float
Cosec=1/Sin(x)
End Function

Function Cot(x As Float) As Float
Cot=1/Tan(x)
End Function

Function Sinh(x As Float) As Float
Sinh=(Exp(x)-Exp(-x))/2
End Function

Function Cosh(x As Float) As Float
Cosh=(Exp(x)+Exp(-x))/2
End Function

Function Tanh(x As Float)v
Tanh=(Exp(-x)/Exp(x)+Exp(-x))*2+1
End Function

Function Sech(x As Float) As Float
Sech=2/(Exp(x)+Exp(-x))
End Function

Function Cosech(x As Float) As Float
Cosech=2/(Exp(x)-Exp(-x))
End Function

Function Coth(x As Float) As Float
Coth=Exp(-x)/(Exp(x)-Exp(-x))*2+1
End Function
'Wolfram Alpha, for x=2.27.  {-1.55374, 1.30658, -0.840928, 4.78804, 4.89136, 0.978879, 0.204442, 0.208854, 1.02158}

Edited 2022-04-23 20:43 by CaptainBoing
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1132
Posted: 04:52pm 23 Apr 2022
Copy link to clipboard 
Print this post

Those first 4 in the second group should be done with ATAN2 instead of ATN.
Visit Vegipete's *Mite Library for cool programs.
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 2170
Posted: 07:57am 24 Apr 2022
Copy link to clipboard 
Print this post

  vegipete said  Those first 4 in the second group should be done with ATAN2 instead of ATN.


I did write the inverse functions (second group) into code and they work OK when you respect the input-value ranges, but the odd 2 or 3 don't agree with Wolfram so some remedial work is required.

There is also a typo in one of them (a bracket missing) but can't remember which off the top of my head EDIT: It's Sech_1

For completeness... I would like to get them all working but I don't think I have ever used them and at my stage of life am unlikely to now. It would be a purely mental exercise.

'Inverse trig functions
Function Sin_1(x As Float)'OK
Sin_1=Atn(x/Sqr(-x*x+1))
End Function

Function Cos_1(x As Float)'OK
Cos_1=-Atn(x/Sqr(-x*x+1))+Pi/2
End Function

Function Sec_1(x As Float)' x>1, value different from Wa
Sec_1=Atn(x/Sqr(x*x-1))+Sgn(Sgn(x)-1)*Pi/2
End Function

Function Cosec_1(x 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)' value different from Wa
Cot_1=Atn(x)+Pi/2
End Function

Function Sinh_1(x As Float)' OK
Sinh_1=Log(x+Sqr(x*x+1))
End Function

Function Cosh_1(x As Float)' OK
Cosh_1=Log(x+Sqr(x*x-1))
End Function

Function Tanh_1(x As Float)' OK
Tanh_1=Log((1+x)/(1-x))/2
End Function

Function Sech_1(x As Float) 'value different from Wa
Sech_1=Log(Sqr(-x*x+1)+1)/x
End Function

Function Cosech_1(x As Float)' OK
Cosech_1=Log((Sgn(x)*Sqr(x*x+1)+1)/x)
End Function

Function Coth_1(x As Float)' OK
Coth_1=Log((x+1)/(x-1))/2
End Function

Edited 2022-04-24 18:35 by CaptainBoing
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 7937
Posted: 08:21am 24 Apr 2022
Copy link to clipboard 
Print this post

I'm sure there must be a use for these. Unfortunately my non A-level brain never could get the hang of anything like that. I used Sin, Cos and Tan at school for something - and not for much else since (at least not with any understanding of what I was doing).

They are very impressive though. :)
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 2170
Posted: 08:48am 24 Apr 2022
Copy link to clipboard 
Print this post

Yes, I agree these are pretty specialist - I think I used a few of them in my radar work 35+ years ago. TBH I only put them here as it scratches my itch to have all the formulae to maths functions and this reference was the most complete I think I have seen, in some obscure book from the 80s and lost to time... perhaps I breathe on the embers to keep the knowledge easy-access. If it never gets used, no harm done.

As far as school-boy trig goes, the most important thing you need to remember (practically, arguably) is:
Reduce everything to right-angle triangles where you can, then use a2+b2=c2. Got me out of a lot of corners that - all the "base" trig functions will give you everything else from that point.

When I was a lad, I was fearless with this stuff. Now-a-days I still try to apply maths to problems as a first step, taking just 5 or 10 minutes to explore can save a lot of pain later, but it takes a lot of effort. I have forgotten so much!
Edited 2022-04-24 18:49 by CaptainBoing
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3378
Posted: 12:20pm 24 Apr 2022
Copy link to clipboard 
Print this post

Back in 1973-4 I used trig to produce output for automating school bus routing using digital maps. This was basically what Google Maps does, except that the output was to a line printer--many sheets wide and many sheets deep. City of Austin, Texas and surrounding Travis County.

I have no idea at this point what functions I used (SIN, COS?) or how I would now use them.
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025