hp41programs

CDGL

Curl, Divergence, Gradient & Laplacian for the HP-41


Overview
 

-A similar program is listed in "Differential Geometry for the HP-41"
-Here, the 1st & 2nd partial derivatives are calculated more quickly,
  but with the same formulas of order 10.

-Thus, "CDGL" is faster and uses less data registers
-On the other hand, the program is longer.

-For complex functions & vector Laplacian, cf "Complex Derivatives and Riemannian Manifolds for the HP-41"
 

>>> LATEST VERSION:
 

-Now, "CDGL" also returns the vector-Laplacian
 

Program Listing
 

 "CDGL"  computes the Curl , divergence, gradient and Laplacian of a 3D-Vector Field   E= ( f , g , h ) = ( X , Y , Z )

      • If the coordinates are rectangular, clear flags F01 & F02
      • If the coordinates are cylindrical, set F01 and clear F02
      • If the coordinates are spherical, set F02                                            ( if F02 & F01 are set, F01 is automatically cleared )

-In the last 2 cases, the HP41 sets the RAD mode automatically.
-Flag F01 is cleared if flag F02 is set ( lines 02-03 ).
 

Formulae:

    •  Rectangular Coordinates x , y , z

  Curl E = ( h/y - g/z , f/z - h/x , g/x - f/y )

  Div E  =  f/x + g/y + h/z

  Grad f = ( f/x , f/y , f/z )       and similar formulae for g & h

  Lapl f  = 2f / x2 + 2f / y2 + 2f / z2      and similar formulae for g & h

-The coordinates of the vector Laplacian are simply the Laplacians of the coordinates
  ( It's not so simple in cylindrical & spherical coordinates... )
 

    •  Cylindrical Coordinates r , f , z

  Curl E = [ (1/r) h/¶f - g/z , f/z - h/r , (1/r) ( g + r g/r - f/¶f ) ]

  Div E  =  f/r + (1/r) f + (1/r) g/¶f + h/z

 Grad f = ( f/r , (1/r) f/¶f , f/z )       and similar formulae for g & h

  Lapl f  = 2f / r2 + (1/r) f/r + (1/r2) 2f / ¶f2 + 2f / z2      and similar formulae for g & h

-For the vector-laplacian, the formulas are given  here
 

    •  Spherical Coordinates r , q , f

  Curl E = [ (1/(r.sin q) ) ( h cos q + sin q h/¶q - g/¶f ) , (1/(r.sin q) ) f/¶f - h/r - h / r , (1/r) ( g + r g/r - f/¶q ) ]

  Div E  = f/r + (2/r) f + g (cos q)/(r sin q)  + (1/r) g/¶q + (1/(r sin q)) h/¶f

 Grad f = ( f/r , (1/r) f/¶q , (1/(r sin q))  f/¶f )       and similar formulae for g & h

  Lapl f  = 2f / r2 + (2/r) f/r + (1/r2) 2f / ¶q2 + (1/(r2tan q)f / ¶q + (1/(r2sin2q)) 2f / ¶f2      and similar formulae for g & h

-For the vector-laplacian, the formula, even more complicated than the cylindrical case, is given here
 
 

Data Registers:              R00 = h        ( at the end )

                                        R01 = x         R04-R05-R06 = Curl E       R08-R09-R10 = Grad (X)    R17 = Lap (X)    R20 to R22 = Vector Laplacian
                                        R02 = y         R07 = Div E                         R11-R12-R13 = Grad (Y)   R18 = Lap (Y)
                                        R03 = z                                                     R14-R15-R16 = Grad (Z)    R19 = Lap (Z)

                                        R23 to R38 contain the same results as R04 to R19

Flags: /
Subroutines:     3 programs named "X"  "Y"  "Z"  which compute X(x,y,z) , Y(x,y,z) and Z(x,y,z)
                            assuming x is in X-register, y is in Y-register and z is in Z-register upon entry.
 
 
 

 01 LBL "CDGL"
 02 FS? 02
 03 CF 01
 04 FC? 01
 05 FS? 02
 06 RAD
 07 "X"
 08 ASTO 00
 09 XEQ 10
 10 STO 22
 11 STO 23
 12 RDN
 13 STO 24
 14 CHS
 15 STO 21
 16 RDN
 17 STO 25
 18 STO 20
 19 X<>Y
 20 STO 32
 21 FS? 02
 22 GTO 02
 23 FS? 01
 24 GTO 01
 25 STO 35
 26 GTO 00
 27 LBL 01
 28 XEQ 04
 29 +
 30 STO 32
 31 RCL 05
 32 RCL 01
 33 ST/ 21
 34 ST/ 24
 35 /
 36 ST+ 22
 37 LASTX
 38 /
 39 -
 40 STO 35
 41 RCL 07
 42 ST+ X
 43 RCL 01
 44 X^2
 45 /
 46 STO 36
 47 GTO 00
 48 LBL 02
 49 XEQ 03
 50 STO 32
 51 STO 35
 52 RCL 01
 53 ST/ 21
 54 ST/ 24
 55 RCL 02
 56 SIN
 57 *
 58 ST/ 20
 59 ST/ 25
 60 RCL 01
 61 *
 62 RCL 08
 63 ST+ X
 64 X<>Y
 65 /
 66 STO 37
 67 RCL 05
 68 ST+ X
 69 RCL 01        
 70 /
 71 ST+ 22
 72 LASTX
 73 /
 74 ST- 35
 75 RCL 07
 76 ST+ X
 77 RCL 01
 78 X^2
 79 /
 80 STO 36
 81 LBL 00
 82 "Y"
 83 XEQ 09
 84 FS? 01
 85 GTO 01
 86 FS? 02
 87 GTO 02
 88 ST+ 21
 89 STO 26
 90 RDN
 91 STO 27
 92 ST+ 22
 93 RDN
 94 STO 28
 95 CHS
 96 STO 19
 97 X<>Y
 98 STO 33
 99 STO 36
100 GTO 00
101 LBL 01
102 XEQ 04
103 +
104 STO 33
105 ST+ 36
106 RCL 06
107 STO 26
108 RCL 07
109 RCL 01
110 /
111 ST+ 22
112 STO 27
113 ST+ X
114 LASTX
115 /
116 ST- 35
117 RCL 08
118 STO 28        
119 CHS
120 STO 19
121 RCL 06
122 RCL 05
123 RCL 01
124 /
125 +
126 ST+ 21
127 LASTX
128 RCL 01
129 /
130 ST- 36
131 GTO 00
132 LBL 02
133 XEQ 03
134 STO 33
135 ST+ 36
136 RCL 06
137 STO 26
138 RCL 07
139 RCL 01
140 /
141 STO 27
142 RCL 08
143 LASTX
144 RCL 02
145 SIN
146 *
147 STO 00
148 /
149 STO 28
150 CHS
151 STO 19
152 CHS
153 ST+ X
154 RCL 01
155 /
156 RCL 02
157 TAN
158 /
159 ST+ 37
160 RCL 05
161 RCL 02
162 TAN
163 /
164 RCL 07
165 +
166 RCL 01
167 /
168 ST+ 22
169 ST+ X
170 LASTX
171 /
172 ST- 35
173 RCL 05
174 RCL 00
175 X^2
176 /
177 ST- 36
178 RCL 05
179 RCL 01
180 /
181 RCL 06
182 +
183 ST+ 21
184 LBL 00
185 "Z"
186 XEQ 09
187 FS? 01
188 GTO 01
189 FS? 02
190 GTO 02
191 STO 29        
192 ST- 20
193 RDN
194 STO 30
195 ST+ 19
196 RDN
197 STO 31
198 ST+ 22
199 X<>Y
200 STO 34
201 STO 37
202 GTO 00
203 LBL 01
204 XEQ 04
205 +
206 STO 34
207 STO 37
208 RCL 06
209 STO 29
210 RCL 07
211 RCL 01
212 /
213 ST+ 19
214 STO 30
215 RCL 08
216 STO 31
217 ST+ 22
218 RCL 06
219 ST- 20
220 GTO 00
221 LBL 02
222 XEQ 03
223 STO 34
224 ST+ 37
225 RCL 06
226 STO 29
227 RCL 07
228 RCL 01
229 /
230 STO 30
231 RCL 08
232 LASTX
233 RCL 02
234 SIN
235 *
236 /
237 STO 31
238 ST+ 22
239 RCL 05
240 LASTX
241 X^2
242 /
243 ST- 37
244 X<>Y
245 ST+ X
246 RCL 01
247 /
248 ST- 35
249 RCL 02
250 TAN
251 /
252 ST- 36
253 RCL 07
254 RCL 05
255 RCL 02
256 TAN
257 /
258 +
259 RCL 01        
260 /
261 ST+ 19
262 RCL 06
263 RCL 05
264 RCL 01
265 /
266 +
267 ST- 20
268 GTO 00
269 LBL 03
270 XEQ 04
271 RCL 02
272 SIN
273 X^2
274 /
275 RCL 07
276 RCL 02
277 TAN
278 /
279 +
280 RCL 01
281 X^2
282 /
283 +
284 RTN
285 LBL 04
286 RCL 10
287 RCL 01
288 /
289 RCL 06
290 FS? 02
291 ST+ X
292 +
293 RCL 01
294 /
295 RCL 09
296 +
297 RCL 11
298 RTN
299 LBL 09
300 ASTO 00
301 RCL 04
302 RCL 03
303 RCL 02
304 RCL 01
305 LBL 10
306 STO 01
307 RDN
308 STO 02
309 RDN
310 STO 03
311 X<>Y
312 STO 04
313 STO 12
314 X<>Y
315 R^
316 R^
317 XEQ IND 00
318 STO 05
319 6
320 ST* 12
321 XEQ 01
322 125
323 ST/ 15
324 ST/ 13
325 /
326 STO 11
327 RCL 15
328 STO 10
329 RCL 13
330 STO 09        
331 RCL 14
332 50
333 ST/ 16
334 ST/ 18
335 /
336 STO 06
337 RCL 16
338 STO 07
339 RCL 18
340 STO 08
341 XEQ 01
342 8
343 ST/ 15
344 ST/ 13
345 /
346 ST- 11
347 RCL 15
348 ST- 10
349 RCL 13
350 ST- 09
351 RCL 14
352 4
353 ST/ 16
354 ST/ 18
355 /
356 ST- 06
357 RCL 16
358 ST- 07
359 RCL 18
360 ST- 08
361 XEQ 01
362 ST+ 11
363 RCL 15
364 ST+ 10
365 RCL 13
366 ST+ 09
367 RCL 14
368 1.5
369 ST* 16
370 ST* 18
371 *
372 ST+ 06
373 RCL 16
374 ST+ 07
375 RCL 18
376 ST+ 08
377 XEQ 01
378 6
379 ST* 15
380 ST* 13
381 ST* 14
382 ST* 16
383 ST* 18
384 *
385 ST- 11
386 RCL 15
387 ST- 10
388 RCL 13
389 ST- 09
390 RCL 14
391 ST- 06
392 RCL 16
393 ST- 07
394 RCL 18
395 ST- 08
396 XEQ 01
397 42
398 ST* 15
399 ST* 13
400 *
401 ST+ 11
402 RCL 15        
403 ST+ 10
404 RCL 13
405 ST+ 09
406 RCL 14
407 21
408 ST* 16
409 ST* 18
410 *
411 ST+ 06
412 RCL 16
413 ST+ 07
414 RCL 18
415 ST+ 08
416 25.2
417 RCL 04
418 *
419 ST/ 06
420 ST/ 07
421 ST/ 08
422 LASTX
423 *
424 ST/ 09
425 ST/ 10
426 ST/ 11
427 RCL 09
428 RCL 10
429 RCL 11
430 +
431 +
432 RCL 08
433 RCL 07
434 RCL 06
435 RTN
436 LBL 01
437 RCL 04
438 ST- 12
439 RCL 03
440 RCL 02
441 RCL 01
442 RCL 12
443 +
444 XEQ IND 00
445 STO 13
446 STO 14
447 RCL 03
448 RCL 02
449 RCL 01
450 RCL 12
451 -
452 XEQ IND 00
453 ST+ 13
454 ST- 14
455 RCL 03
456 RCL 02
457 RCL 12
458 +
459 RCL 01
460 XEQ IND 00
461 STO 15
462 STO 16
463 RCL 03
464 RCL 02
465 RCL 12
466 -
467 RCL 01
468 XEQ IND 00
469 ST+ 15
470 ST- 16
471 RCL 03        
472 RCL 12
473 +
474 RCL 02
475 RCL 01
476 XEQ IND 00
477 STO 17
478 STO 18
479 RCL 03
480 RCL 12
481 -
482 RCL 02
483 RCL 01
484 XEQ IND 00
485 ST- 18
486 RCL 17
487 +
488 RCL 05
489 ST+ X
490 ST- 13
491 ST- 15
492 -
493 RTN
494 LBL 00
495 RCL 04
496 STO 00
497 19.004019
498 REGMOVE
499 4.022
500 SIGN
501 RCL 07
502 RCL 06
503 RCL 05
504 RCL 04
505 END

 
     ( 769 bytes /SIZE 039 )
 
 

      STACK       INPUTS      OUTPUTS
           T            h         Div E
           Z            x3        Curl3 E
           Y            x2        Curl2 E
           X            x1        Curl1 E
           L             /         4.022

    4.022 = control number of all the results.

Example1 - Rectangular Coordinates:   CF 01  CF 02

   E = ( f , g , h )  = [ exp(-x2) Ln(y2+z) , x2y2z2 , exp(x) y2z ]     With  x = 1 , y = 2 , z = 3

-Load the short routines:
 
 

 01  LBL "X"
 02  X^2
 03  CHS
 04  E^X
 05  RDN
 06  X^2
 07  +
 08  LN
 09  R^
 10  *
 11  RTN 
 12  LBL "Y"
 13  *
 14  *
 15  X^2
 16  RTN
 17  LBL "Z"
 18  E^X
 19  RDN
 20  X^2
 21  *
 22  R^
 23  *
 24  RTN

 
      CF 01   CF 02

-If you choose  h = 0.1

  0.1  ENTER^
   3    ENTER^
   2    ENTER^
   1    XEQ "CDGL+"  >>>>     8.619381890  = R04                                                                    ---Execution time = 90s---
                                   RDN    -32.56682780  = R05
                                   RDN     71.78978318  = R06
                                   RDN     45.44140669  = R07

-So,  Curl E = ( 8.619381890 ,  -32.56682780 ,  71.78978318 )

 and    Div E = 45.44140669

-You also find in registers R08 to R19:

    Grad f = ( -1.431720683 , 0.210216822 , 0.052554204 )
    Grad g = ( 72 , 36 , 24 )
    Grad h = ( 32.61938200 , 32.61938189 , 10.87312737 )

    Lapl f = 1.409197689
    Lapl g = 98                               which are also in R20 thru R22
    Lapl h = 48.92907013
 

Example2 - Cylindrical Coordinates:   SF 01  CF 02

   E = ( f , g , h )  = (  r z2 sin2f , r2 z , r3 z cos f )                   r = 2 , f = PI/5 , z = 1
 
 
 

 01  LBL "X"
 02  RDN
 03  SIN
 04  *
 05  X^2
 06  R^
 07  *
 08  RTN
 09  LBL "Y"
 10  X^2
 11  RCL Z
 12  *
 13  RTN
 14  LBL "Z"
 15  X^2
 16  LASTX
 17  *
 18  X<>Y
 19  COS
 20  *
 21  *
 22  RTN

 
    SF 01   CF 02

-If you choose  h = 0.1

     0.1   ENTER^
       1
   PI  5  /
      2    R/S   >>>>    -6.351141010  = R04                                                                     ---Execution time = 94s---
                     RDN    -8.326237923  = R05
                     RDN     5.048943482  = R06
                     RDN     7.163118954  = R07

-So,  Curl E = ( -6.351141010 ,  -8.326237923 ,  5.048943482 )

 and    Div E = 7.163118954

-You also find in registers R08 to R19:

    Grad f = ( 0.345491503 , 0.951056518 , 1.381966010 )
    Grad g = ( 4 , 0 , 4 )
    Grad h = ( 9.708203933 , -2.351141010 , 6.472135948 )

    Lapl f = 1.863728736
    Lapl g = 4
    Lapl h = 12.94427209

-And the coordinates of the vector-laplacian in R20 to R22

  VLap =  ( 1.690982985 , 3.951056518 , 12.94427209 )

-In cylindrical coordinates, the 3rd coordinate of the vector-laplacian = the Laplacian of the 3rd coordinate.
-This is not true in spherical coordinates:
 

Example2 - Spherical Coordinates:    CF 01  SF 02
 

   E = ( f , g , h )  = (  r sin2 q cos2 f , r2sin f  , r3 cos q cos2 f )                   r = 2 , q = PI/3 , f = PI/5
 
 
 

 01  LBL "X"
 02  RDN
 03  SIN
 04  X<>Y
 05  COS
 06  *
 07  X^2
 08  R^
 09  *
 10  RTN
 11  LBL "Y"
 12  X^2
 13  RCL Z
 14  SIN
 15  *
 16  RTN
 17  LBL "Z"
 18  X^2
 19  LASTX
 20  *
 21  X<>Y
 22  COS
 23  *
 24  X<>Y
 25  COS
 26  X^2
 27  *
 28  RTN

 
   CF 01    SF 02

-If you choose  h = 0.1

     0.1
   PI  5  /
   PI  3  /
      2    R/S   >>>>   -3.379867348  = R04                                                                     ---Execution time = 145s---
                     RDN    -6.059707088  = R05
                     RDN     2.959890530  = R06
                     RDN    -0.045010876  = R08

-So,  Curl E = ( -3.379867348 ,  -6.059707088 ,  2.959890530 )

 and    Div E = -0.045010876

-You also find in registers R08 to R19:

    Grad f = ( 0.490881375 , 0.566820985 , -0.823639103 )
    Grad g = ( 2.351141010 , 0 , 1.868344718 )
    Grad h = ( 3.927050990 , -2.267283945 , -2.196370945 )

    Lapl f = 0.018237234
    Lapl g = 2.742997604
    Lapl h = 5.721039300

-And the coordinates of the vector-laplacian in R20 to R22

  VLap =  ( 1.045010859 , 3.794180276 , 5.103411526 )