Post Reply 
Contour Integral
11-12-2023, 07:22 PM
Post: #1
Contour Integral
Hi!
I upload a document with the same program from the Advanced Functions Handbook for the HP 15C to approximate the Contour Integral of a complex Function F(z). The same example function is also program under the label FZ. The evaluation take 17 minutes 11 seconds!

Brian Zilli do a general form with the same example function for the HP 15C.

The HP 41C can do the math like the HP 15C! (With more time...)

Marcel


Attached File(s)
.pdf  Contour Integral (41CX) PDF.pdf (Size: 273.72 KB / Downloads: 46)
Find all posts by this user
Quote this message in a reply
02-25-2024, 09:31 AM (This post was last modified: 03-03-2024 01:40 PM by Ángel Martin.)
Post: #2
RE: Contour Integral
Thanks for putting this one together, nicely done indeed.

I have made a few tweaks that save some bytes and eliminate one global label. Plus also used the 41Z functions instead of the FOCAL routines from the Advantage, which make the code better legible and reduces execution time. The resulting code is posted below.

This application is somewhat limited to (non-horizontal) straight line segments for contours, I've been musing about a general-purpose implementation using the residues theorem and analytical functions but so far the challenge is not resolved... would like to hear if anybody has some suggestions.

Code:
01  LBL “ZLITG” Cpx. Line Intg.
02  ASTO 00
03  Z<>W        saves a in ZR03
04  ZSTO 03     Re in R06, IM in R07
05  Z-          saves b-a in ZR04
06  ZSTO 04     Re in R08, Im in R09
07  “ITG”       integrands
08  0           t1 limit
09  ENTER^
10  1           t2 limit
11  SF 01       Imaginary parts
12  FINTG       calculates Im (I, ?)
13  STO 02      saves Im(I) in R02
14  RDN
15  STO 04      saves Im(DI) in R03
16  RDN         same limits
17  CF 01       flag real parts
18  FINTG       calculates Re(I, D)
19  STO 01      saves Re(I) in R01
20  X<>Y
21  STO 03      saves Re(DI) in R03
22  RCL 04      presents DI in W
23  X<>Y
24  ZENTER^     saves DI in W
25  RCL 02      presents I in Z
26  RCL 01
27  ZAVIEW      shows result     
28  TONE 2
29  RTN         done.
30  LBL “ITG”   Integrals
31  0           pure real
32  R^          current t
33  ZRC* 04     (b-a).t
34  ZRC+ 03     z = a +(b-a).t
35  XEQ IND 00  f(z)
36  ZRC* 04     f(z).z’(t)
37  FS? 01      Imaginary?
38  X<>Y        yes, use it 
39  END         done.

and the complex function example:
Code:
01  LBL “FZ”
02  ZENTER^
03  ZINV    1/z
04  LASTZ   z    
05  Z+      z+1/z
06  ZINV    1/(z+1/z)
07  Z<>W    z
08  Z*I     can be replaced with {X<>Y, CHS}
09  ZEXP    exp(iz)
10  Z*      f(z)
11  END

Usage: set the desired accuracy (i.e. FIX 3), enter the complex function LABEL in ALPHA (i.e. "FZ"), and the lower and upper complex limits in the complex stack (i.e. 0, ENTER^, 1, ZENTER^, 6, ENTER^, 1). Then execute the program (i.e. XEQ "ZLITG")

Result in FIX 6: -0.324350+J0.382053

Best,
ÁM

"To live or die by your own sword one must first learn to wield it aptly."
Find all posts by this user
Quote this message in a reply
02-25-2024, 08:06 PM
Post: #3
RE: Contour Integral
Hi Ángel!

Thank you for your comment!

Can you post the running time for your version with the same exemple..

Marcel
Find all posts by this user
Quote this message in a reply
02-25-2024, 09:57 PM
Post: #4
RE: Contour Integral
Hi Marcel, I haven't used it on a real machine yet, but on V41 with default settings it took 4 min and 22 sec with a FIX3.

Using TURBO however it takes just above 17 seconds - but of course that would be cheating :=)

BTW I just noticed your mention to Brian Zilli - can you elaborate on that? I'd be curious to check other examples as well.

Cheers,
ÁM

"To live or die by your own sword one must first learn to wield it aptly."
Find all posts by this user
Quote this message in a reply
02-25-2024, 10:50 PM (This post was last modified: 02-25-2024 10:51 PM by Marcel.)
Post: #5
RE: Contour Integral
Hi again!

This post.

Marcel
Find all posts by this user
Quote this message in a reply
02-26-2024, 07:43 AM (This post was last modified: 02-28-2024 06:56 PM by Ángel Martin.)
Post: #6
RE: Contour Integral
(02-25-2024 10:50 PM)Marcel Wrote:  This post.

Thanks, I had completely missed that thread and it's well worth a detailed read.

Here's my take at the updated programs, using an initial data entry section and a runtime execution entry point at LBL C
(*) PMTA is available in the OS/X modules

Code:
01  LBL "ZCNTR" main driver program
02  "FZ? "      global LBL name
03  PMTA        for f(z) routine
04  ASTO 02     saved in R02
05  "Z(T)? "    global label name
06  PMTA        for z(t) routine
07  ASTO 00     saved in R00
08  "Z'(T)? "   global LBL name
09  PMTA        for z'(t) routine
10  ASTO 01     saved in R01
11  "R=?"       magnitude of radious    
12  PROMPT      (ignore if not needed)
13  STO 03      saved in R03
14  "T1^T2=?"   integration limits
15  PROMPT      for parameter t    
16  STO 05      t2 saved in R05
17  X<>Y   
18  STO 04      t1 saved in R04
19  LBL C       for repeat use
20  RCL 04      lower limit t1            
21  RCL 05      upper limit t2
22  "ITG"       integrand routine
23  SF 00       flags Imaginary parts
24  FINTG       does the integration
25  STO 06      saves Im(I) in R06
26  X<>Y
27  STO 07      saves D(Im(I))                    
28  CF 00       flags Real parts
29  RCL 04      lower limit t1
30  RCL 05      upper limit t2
31  FINTG       does the integration
32  STO 08      saves Re(I) 
33  X<>Y    
34  STO 09      saves D(Re(I))
35  RCL 07      D(Im(I))
36  X<>Y        D(Re(I))
37  ZENTER^     pushes D in level W
38  RCL 08      Im(I)
39  RCL 06      Re(I)
40  ZAVIEW      shows result
41  TONE 2    
42  RTN         done. 
43  LBL "ITG"   Integrand routine
44  STO 08      saves t in R08
45  XEQ IND 00  calculates z(t)
45  XEQ IND 02  calculates f(z(t))
46  ZSTO 05     saves f(z) in ZR 05
47  RCL 08      recalls t
48  XEQ IND 01  calculates z'(t)
49  ZRC* 05     z'(t).f(z)
50  FS? 00      Imaginary?    
51  X<>Y        yes, take Im part
52  END

as well as the parameterized curves z(t) and z'(t) - The routine for f(z) is the same one used in the initial program, see the second post in this thread.

Code:
01  LBL "ZT"    parameterized z
02  XEQ "ZP"    opportunistic
03  1           adds anchor    
04  +
05  RTN
06  LBL "ZP"    derivative 
07  0           pure imaginary (0+it)
08  ZEXP        exp(it)
09  RCL 03      R
10  ST* Z
11  *           R.exp(it)
12  END         done.

The results obtained are the same as those presented in Brian Zilli's paper.

Enjoy!

"To live or die by your own sword one must first learn to wield it aptly."
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)