hp41programs

CURVELENGTH

Arc Length of a Parametric Curve for the HP-41


Overview
 

 1°) 3-Dimensional Problem

   a) Program#1
   b) Program#2

 2°) N-Dimensional Problem

   a) Program#1
   b) Program#2  ( N < 10 )
 
 

-In paragraph 1, we assume that the curve is defined by 3 functions  X(t) , Y(t) , Z(t)
-Likewise, in paragraph 2, the curve is defined by N functions   X1(t) , X2(t) , .......... , XN(t)
 
 

1°)  3-Dimensional Problem
 

     a) Program#1
 

 "CRVL" evaluates the integral  §ab  [ ( dX/dt )2 + ( dY/dt )2 + ( dZ/dt )2 ] 1/2  dt
 

-The derivatives are estimated by our usual formula of order 10

       df/dx ~ (1/2520.h).[ 2100.( f1 - f-1 ) - 600.( f2 - f-2 ) + 150.( f3 - f-3 ) - 25.( f4 - f-4 ) + 2.( f5 - f-5 ) ]

    (  f(x+k.h) is denoted fk to simplify these expressions )

-And the integral is approximated by Newton-Cotes 7-point formula:

   §x1x7  f(x).dx  ~  h [ 41f(x1)+216f(x2)+27f(x3)+272f(x4)+27f(x5)+216f(x6)+41f(x7) ] / 140    with   xi+1 - xi = h = Cste

-The intervall [a,b] may be divided into m parts to get more and more accurate results.
 
 

Data Registers:             R00:  temp

                                        R01 = a      R04 = h      R06 to R13: temp
                                        R02 = b      R05 = L
                                        R03 = m
Flags: /
Subroutine:  3 programs named  "X"  "Y"  "Z"   that take t in X-register and return  X(t) , Y(t) , Z(t) respectively  in X-register
 
 
 

 01 LBL "CRVL"
 02 STO 02
 03 X<>Y
 04 STO 01 
 05 -
 06 X<>Y
 07 STO 03
 08 6
 09 *
 10 STO 07
 11 /
 12 STO 06
 13 X<>Y
 14 STO 04        
 15 6
 16 *
 17 STO 09
 18 XEQ 00
 19 41
 20 *
 21 STO 05
 22 DSE 07
 23 GTO 01
 24 LBL 00
 25 RCL 06
 26 RCL 07
 27 *
 28 RCL 01
 29 +
 30 STO 11 
 31 "X"
 32 XEQ 02
 33 X^2
 34 STO 13
 35 "Y"
 36 XEQ 02
 37 X^2
 38 ST+ 13
 39 "Z"
 40 XEQ 02
 41 X^2
 42 RCL 13
 43 +
 44 SQRT
 45 RTN
 46 LBL 02
 47 ASTO 00
 48 RCL 09        
 49 STO 10
 50 XEQ 03
 51 ST+ X
 52 STO 08
 53 XEQ 03
 54 25
 55 *
 56 ST- 08
 57 XEQ 03
 58 150
 59 *
 60 ST+ 08
 61 XEQ 03
 62 600
 63 *
 64 ST- 08
 65 XEQ 03
 66 2100
 67 *
 68 RCL 08 
 69 +
 70 RCL 04        
 71 2520
 72 *
 73 /
 74 RTN
 75 LBL 03
 76 RCL 04
 77 ST- 10
 78 RCL 11
 79 RCL 10
 80 -
 81 XEQ IND 00
 82 STO 12
 83 RCL 11
 84 RCL 10
 85 +
 86 XEQ IND 00
 87 RCL 12        
 88 -
 89 RTN
 90 LBL 01
 91 XEQ 00
 92 216
 93 *
 94 ST+ 05
 95 DSE 07
 96 XEQ 00
 97 27
 98 *
 99 ST+ 05
100 DSE 07
101 XEQ 00
102 272
103 *
104 ST+ 05
105 DSE 07
106 XEQ 00
107 27
108 *
109 ST+ 05
110 DSE 07
111 XEQ 00
112 216
113 *
114 ST+ 05
115 DSE 07
116 CLX
117 XEQ 00
118 STO M
119 82
120 *
121 ST+ 05
122 DSE 07
123 GTO 01
124 CLX
125 X<> M
126 41
127 *
128 ST- 05
129 RCL 05 
130 RCL 06        
131 *
132 140
133 /
134 STO 05
135 END

 
        ( 228 bytes / SIZE 014 )
 
 

      STACK        INPUTS      OUTPUTS
           T             h             /
           Z             m             /
           Y             a             /
           X             b        L(a,b)

 
Example:    X(t) = t4 ,  Y(t) = t2  ,  Z(t) = exp t   ;  a = 0 ,  b = 1
 
 

 01  LBL "X"
 02  X^2
 03  X^2
 04  RTN
 05  LBL "Y"
 06  X^2
 07  RTN
 08  LBL "Z"
 09  E^X
 10  RTN

 
-With  h = 0.1  and  m = 1

    0.1   ENTER^
     1     ENTER^
     0     ENTER^
     1     XEQ "CRVL"  >>>>   L = 2.342185019                        ---Execution time = 127s---

-With  m = 2 - and the same h-value -  it yields   L = 2.342115991

-The exact result is  L = 2.342116459....
 

     b) Program#2
 

-This variant uses Pythagoreas theorem and Romberg method to evaluate the integral
 
 

Data Registers:          •  R00 = n                                               ( Register R00 is to be initialized before executing "CRVL" )

                                        R01 = a      R03 = L     R04 to R16......: temp
                                        R02 = b
Flags: /
Subroutine:  1 program  that takes t in X-register and R07 and returns  X(t) , Y(t) , Z(t) in registers X , Y , Z  respectively
 

-Line 96 is a three-byte GTO 01
 
 

 01 LBL "CRVL"
 02 STO 02
 03 X<>Y
 04 STO 01
 05 1
 06 STO 04
 07 LBL 01
 08 RCL 02
 09 RCL 01
 10 -
 11 RCL 04
 12 STO 05
 13 /
 14 STO 11
 15 CLX
 16 STO 06
 17 RCL 02
 18 STO 07        
 19 XEQ IND 00
 20 STO 08
 21 RDN
 22 STO 09
 23 X<>Y
 24 STO 10
 25 LBL 02
 26 RCL 05
 27 RCL 11
 28 ST* Y
 29 -
 30 RCL 01
 31 +
 32 STO 07
 33 XEQ IND 00
 34 ENTER
 35 X<> 08
 36 -
 37 X^2
 38 X<>Y
 39 ENTER
 40 X<> 09
 41 -
 42 X^2
 43 +
 44 X<>Y
 45 ENTER
 46 X<> 10
 47 -
 48 X^2
 49 +
 50 SQRT
 51 ST+ 06
 52 DSE 05
 53 GTO 02
 54 RCL 06        
 55 SIGN
 56 ST* X
 57 RCL 04
 58 ST+ 04
 59 X#Y?
 60 GTO 00
 61 STO 14
 62 LASTX
 63 STO 16
 64 GTO 01
 65 LBL 00
 66 4
 67 STO 12
 68 16
 69 STO 13
 70 RCL 14
 71 STO 15        
 72 LASTX
 73 ISG 14
 74 LBL 03
 75 ENTER
 76 ENTER
 77 X<> IND 13
 78 -
 79 RCL 12
 80 4
 81 ST* 12
 82 SIGN
 83 ST+ 13
 84 -
 85 /
 86 +
 87 DSE 15
 88 GTO 03
 89 STO 03        
 90 STO IND 13
 91 VIEW X
 92 RND
 93 X<>Y
 94 RND
 95 X#Y?
 96 GTO 01
 97 RCL 03
 98 END

 
        ( 132 bytes / SIZE 016+??? )
 
 

      STACK        INPUTS      OUTPUTS
           Y             a             /
           X             b         L(a,b)

 
Example:    X(t) = t4 ,  Y(t) = t2  ,  Z(t) = exp t   ;  a = 0 ,  b = 1
 
 

 01  LBL "T"
 02  E^X
 03  LASTX
 04  X^2
 05  ENTER^
 06  X^2
 07  RTN

 
-If you try 9 decimals

     T  ASTO 00
     FIX 9

     0     ENTER^
     1     XEQ "CRVL"  >>>>   L = 2.342116456                        ---Execution time = 97s---
 

Notes:

-The HP41 displays the successive approximations.
-The result depends on the display format ( lines 92-94 )
-The exact result is  L = 2.342116459....
 

2°)  N-Dimensional Problem
 

     a) Program#1
 

 "CRVLN" evaluates the integral  §ab  [ ( dX1/dt )2 + ( dX2/dt )2 + ............ + ( dXN/dt )2 ] 1/2  dt
 

-The derivatives and the integral are estimated by the same formulas of order 10.

-The inervall [a,b] may be divided in m parts to get more and more accurate results.
 

Data Registers:             R00:  temp

                                        R01 = a      R04 = h      R06 to R15: temp
                                        R02 = b      R05 = L
                                        R03 = m
Flags: /
Subroutine:  N programs named  "X1"  "X2" ............. "XN"   that take t in X-register and return  X1(t) , X2(t) , .......... , XN(t) respectively  in X-register
 
 
 

 01 LBL "CRVLN"
 02 "DIM=?"
 03 PROMPT
 04 STO 14          
 05 "H^M^A^B"
 06 PROMPT
 07 STO 02 
 08 X<>Y
 09 STO 01
 10 -
 11 X<>Y
 12 STO 03
 13 6
 14 *
 15 STO 07
 16 /
 17 STO 06
 18 X<>Y
 19 STO 04
 20 6
 21 *
 22 STO 09
 23 FIX 0
 24 CF 29
 25 XEQ 00
 26 41
 27 *
 28 STO 05          
 29 DSE 07
 30 GTO 01
 31 LBL 00
 32 RCL 06 
 33 RCL 07
 34 *
 35 RCL 01
 36 +
 37 STO 11
 38 CLX
 39 STO 13
 40 RCL 14
 41 STO 15
 42 LBL 04
 43 "X"
 44 ARCL 15
 45 XEQ 02
 46 X^2
 47 ST+ 13
 48 DSE 15
 49 GTO 04
 50 RCL 13
 51 SQRT
 52 RTN
 53 LBL 02
 54 ASTO 00
 55 RCL 09          
 56 STO 10 
 57 XEQ 03
 58 ST+ X
 59 STO 08
 60 XEQ 03
 61 25
 62 *
 63 ST- 08
 64 XEQ 03
 65 150
 66 *
 67 ST+ 08
 68 XEQ 03
 69 600
 70 *
 71 ST- 08
 72 XEQ 03
 73 2100
 74 *
 75 RCL 08
 76 +
 77 RCL 04
 78 2520
 79 *
 80 /
 81 RTN
 82 LBL 03
 83 RCL 04          
 84 ST- 10
 85 RCL 11
 86 RCL 10 
 87 -
 88 XEQ IND 00
 89 STO 12
 90 RCL 11
 91 RCL 10
 92 +
 93 XEQ IND 00
 94 RCL 12
 95 -
 96 RTN
 97 LBL 01
 98 XEQ 00
 99 216
100 *
101 ST+ 05
102 DSE 07 
103 XEQ 00
104 27
105 *
106 ST+ 05
107 DSE 07
108 XEQ 00
109 272
110 *
111 ST+ 05
112 DSE 07         
113 XEQ 00
114 27
115 *
116 ST+ 05
117 DSE 07
118 XEQ 00
119 216
120 *
121 ST+ 05
122 DSE 07
123 CLX
124 XEQ 00
125 STO M
126 82
127 *
128 ST+ 05
129 DSE 07         
130 GTO 01
131 CLX
132 X<> M
133 41
134 *
135 ST- 05
136 RCL 05 
137 RCL 06
138 *
139 140
140 /
141 STO 05
142 FIX 9
143 SF 29
144 END

 
     ( 251 bytes / SIZE 016 )
 
 

      STACK        INPUT      OUTPUT
           X             /         L(a,b)

 
Example:    X1(t) = t4 ,  X2(t) = t2  ,  X3(t) = t3  ,  X4(t) = exp t   ;  a = 0 ,  b = 1
 
 
 

 01  LBL "X1"
 02  X^2
 03  X^2
 04  RTN
 05  LBL "X2"
 06  X^2
 07  RTN
 08  LBL "X3"
 09  ENTER^
 10  X^2
 11  *
 12  RTN
 13  LBL "X4"
 14  E^X
 15  RTN

 
-With  h = 0.1  and  m = 1

    XEQ "CRVLN"  >>>>  "DIM=?"

               4               R/S    "H^M^A^B"

             0.1   ENTER^
               1    ENTER^
               0    ENTER^
               1        R/S          >>>>      L = 2.579075091                        ---Execution time = 180s---

-With  m = 2 - and the same h-value -  it yields   L = 2.579079247

-The exact result is  L = 2.579079231....
 

     b) Program#2  ( n < 10 )
 

-Like the 2nd version of "CRVL", this variant of "CRVLN" uses an extrapolation to the limit.
 
 

Data Registers:             R00 = n

                                        R01 = a      R03 = L     R04 to R26......: temp
                                        R02 = b
Flags: /
Subroutine:  N programs named  "X1"  "X2" ....... "XN"   that take t in X-register & R07 and return  X1(t) , X2(t) , ....... , XN(t) respectively  in X-register

-Line 115 is a three-byte GTO 01
 
 

 01 LBL "CRVLN"
 02 STO 02
 03 RDN
 04 STO 01
 05 X<>Y
 06 STO 00          
 07 1
 08 STO 04
 09 RCLFLAG
 10 STO 20
 11 LBL 01
 12 FIX 00
 13 CF 29
 14 RCL 00
 15 STO 18
 16 17
 17 STO 19
 18 LBL 02
 19 "X"
 20 ARCL 18
 21 ASTO L
 22 RCL 02
 23 STO 07
 24 XEQ IND L
 25 STO IND 19
 26 DSE 19
 27 DSE 18
 28 GTO 02
 29 CLX
 30 STO 06
 31 RCL 02          
 32 RCL 01
 33 -
 34 RCL 04
 35 STO 05
 36 /
 37 STO 08
 38 LBL 03
 39 RCL 05
 40 RCL 08
 41 ST* Y
 42 -
 43 RCL 01
 44 +
 45 STO 07
 46 RCL 00
 47 STO 18
 48 17
 49 STO 19
 50 CLX
 51 STO 21
 52 LBL 04
 53 "X"
 54 ARCL 18
 55 ASTO L
 56 RCL 07
 57 XEQ IND L
 58 ENTER
 59 X<> IND 19
 60 -
 61 X^2
 62 ST+ 21
 63 DSE 19
 64 DSE 18
 65 GTO 04
 66 RCL 21          
 67 SQRT
 68 ST+ 06
 69 DSE 05
 70 GTO 03
 71 RCL 20
 72 STOFLAG
 73 RCL 06
 74 SIGN
 75 ST* X
 76 RCL 04
 77 ST+ 04
 78 X#Y?
 79 GTO 00
 80 STO 24
 81 LASTX
 82 STO 26
 83 GTO 01
 84 LBL 00
 85 4
 86 STO 22
 87 26
 88 STO 23          
 89 RCL 24
 90 STO 25
 91 LASTX
 92 ISG 24
 93 LBL 05
 94 ENTER
 95 ENTER
 96 X<> IND 23
 97 -
 98 RCL 22          
 99 4
100 ST* 22
101 SIGN
102 ST+ 23
103 -
104 /
105 +
106 DSE 25
107 GTO 05
108 STO 03
109 STO IND 23
110 VIEW X
111 RND
112 X<>Y
113 RND
114 X#Y?
115 GTO 01
116 RCL 03
117 END

 
        ( 184 bytes / SIZE 026+??? )
 
 

      STACK        INPUTS      OUTPUTS
           Z          n < 10             /
           Y             a             /
           X             b         L(a,b)

 
Example:    X1(t) = t4 ,  X2(t) = t2  ,  X3(t) = t3  ,  X4(t) = exp t   ;  a = 0 ,  b = 1
 
 
 

 01  LBL "X1"
 02  X^2
 03  X^2
 04  RTN
 05  LBL "X2"
 06  X^2
 07  RTN
 08  LBL "X3"
 09  ENTER^
 10  X^2
 11  *
 12  RTN
 13  LBL "X4"
 14  E^X
 15  RTN

 
-If you try to find 9 decimals

    FIX 9

    4   ENTER^
    0   ENTER^
    1   XEQ "CRVLN"  >>>>      L = 2.579079231                                ---Execution time = 4m16s---

Notes:

-The HP41 displays the successive approximations.
-The result depends on the display format ( lines 111-113 )
-The exact result is  L = 2.579079231....

-So, there is no roundoff error in this example ( this is not always the case... ).