Post Reply 
Contour Integral
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
Post Reply 


Messages In This Thread
Contour Integral - Marcel - 11-12-2023, 07:22 PM
RE: Contour Integral - Ángel Martin - 02-25-2024 09:31 AM
RE: Contour Integral - Marcel - 02-25-2024, 08:06 PM
RE: Contour Integral - Ángel Martin - 02-25-2024, 09:57 PM
RE: Contour Integral - Marcel - 02-25-2024, 10:50 PM
RE: Contour Integral - Ángel Martin - 02-26-2024, 07:43 AM
RE: Contour Integral - jonmoore - 08-12-2024, 11:20 AM



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