hp41programs

hyperbolics

Hyperbolic Functions for the HP-41


Overview
 

-This program computes the hyperbolic sine, cosine, tangent, the Gudermannian function and their inverses.
-I've used  E^X-1 & LN1+X instead of  E^X & LNX in order to achieve a good accuracy for small arguments too.
 

Formulae:

   Sh x = Sinh x = [ ( ex - 1 ) - ( e -x - 1 ) ]/2                                Ash x = Asinh x = Ln [ 1 + x + x2 / ( 1 + ( 1 + x2 )1/2 ) ]
   Ch x = Cosh x = ( ex + e -x )/2                                                 Ach x = Acosh x = Ln [ 1 + ( x - 1 ) + ( ( x + 1 )( x - 1 ) )1/2 ]
   Th x = Tanh x = ( e2x - 1 )/( e2x + 1 )                                       Ath x = Atanh x = (1/2).Ln ( 1 + 2x/( 1 - x ) )
   Gd x = 2.Arctan ( ex ) - Pi/2 = 2.Arctan ( tanh x/2 )                 Agd x = Ln Tan ( x/2 + Pi/4 ) = 2.Atanh ( tan x/2 )
 

Program Listing
 
 

01  LBL "SH"
02  E^X-1
03  LASTX
04  CHS
05  E^X-1
06  -
07  2
08  /
09  RTN
10  LBL "CH"   
11  E^X
12  LASTX
13  CHS
14  E^X
15  +
16  2
17  /
18  RTN
19  LBL "TH"
20  ST+ X
21  LBL 01
22  E^X-1
23  RCL X
24  2
25  +
26  /
27  RTN
28  LBL "GD"
29  XEQ 01
30  RAD
31  ATAN
32  DEG
33  ST+ X
34  RTN
35  LBL "ASH"
36  SIGN
37  LASTX
38  ABS
39  ENTER^
40  X^2
41  1
42  +
43  SQRT
44  1
45  +
46  RCL Y
47  X^2
48  X<>Y
49  /
50  +
51  LN1+X
52  *
53  RTN
54  LBL "ACH"
55  1
56  -
57  ENTER^
58  STO Z
59  2
60  +
61  *
62  SQRT
63  +
64  LN1+X
65  RTN
66  LBL "ATH"
67  XEQ 02
68  2
69  /
70  RTN
71  LBL "AGD"
72  2
73  /
74  RAD
75  TAN
76  DEG
77  LBL 02
78  SIGN
79  LASTX      
80  ABS
81  ENTER^
82  ST+ Y
83  CHS
84  1
85  +
86  /
87  LN1+X
88  *
89  END

 
  ( 145 bytes / SIZE 000 )
 
 

      STACK         INPUT      OUTPUT
           X             x         hyp(x)

Examples:

  2  XEQ "SH"   >>>>  Sinh 2  =  3.626860408
  2  XEQ "CH"  >>>>  Cosh 2 =  3.762195691
  2  XEQ "TH"  >>>>   Tanh 2 =  0.964027580
  2  XEQ "GD"  >>>>   Gd 2   =  1.301760336

 14   XEQ "ASH"  >>>>  Asinh 14  = 3.333477587
 14   XEQ "ACH" >>>>  Acosh 14 = 3.330926553
 0.7  XEQ "ATH"  >>>>  Atanh 0.7 = 0.867300528
 0.7  XEQ "AGD"  >>>>  Agd 0.7   = 0.765350459

Remarks:

-If the function f  is  Asinh , Atanh or Agd , and if  x < 0 , this program calculates  -f(-x)
 to avoid a loss of accuracy for large negative arguments.
-For instance,  Asinh 12000 = 10.08580911  whence  Asinh (-12000) = -10.08580911
-Otherwise, it would give  -10.12663110 ( like the Math Pac ) by cancellation of significant digits.

-One may also write several variations, for example:

 Hyperbolic cosine for small arguments:

  LBL "CHX-1"
  E^X-1
  LASTX
  CHS
  E^X-1
  +
  2
  /
  RTN

 Hyperbolic tangent for large positive arguments:

  LBL "1-THX"
  ST+ X
  E^X
  1
  +                   for example:   12  XEQ "1-THX"  >>>>  7.550269089 10 -11  whence  Tanh 12 = 0.999,999,999,924,497,309,11
  2
  X<>Y
  /
  RTN

 Inverse hyperbolic cosine for small arguments:

-Simply add  LBL "ACH1+X"  after line 56

 Inverse hyperbolic tangent for arguments close to 1:

  LBL "ATH1-X"
  ENTER^
  CHS
  1
  +
  ST+ X                   for example:   EEX 12 CHS  XEQ "ATH1-X"  >>>>  Atanh ( 0.999999999999 ) = 14.16208415
  X<>Y
  /
  LN1+X
  2
  /
  RTN

 ... and so on ...