Post Reply 
(DM42) Matrix exponential
08-13-2023, 09:41 PM
Post: #10
RE: (DM42) Matrix exponential
Hi Gil,

I corrected some bad logic for small values and also done some time-optimizing
For convergency test 1e-16, i.e. about 16 correct digits:
DM42 on USB calculates the example in 0.67 s
DM42 on battery 1.76 s

Actually setting convergency test to 1e-12, and R03=8, I can run calculations in 0.6 s on USB power and get 12 correct digits Smile
I think it is worth the increased program size.

Code:

@ Matrix exponential, square matrix
@ calculation with argument reduction and series expansion
@ convergence check uses RNRM difference between iterations,
@ uses R00-R03
@ R00: counter, number of iterations
@ R01: convergence limit,  set at line 37,  typical R01=1e-16 to R01=1e-32
@ R02: number of halvings and squarings used for argument reduction
@ R03: number of initial iterations before convergence check (saves time), 
@   suggest R03=10 when R01=1e-16 
@   suggest R03=20 when R01=1e-32 
@ Optional CF 24, CF 25 for overflow check

00 { 121-Byte Prgm }
01▸LBL "MEXP" 
02 FUNC 11     @ 1 argument required, square matrix
03 L4STK
04 10
05 STO 03
06 CLX
07 2
08 STO 00
09 RCL ST Y    @ calculate and determine any argument reduction
10 FNRM
11 LN
12 RCL 00
13 LN
14 ÷
15 IP
16 3           @ reduce the argument a little more
17 +
18 1
19 STO 01
20 +
21 X<0?
22 CLX         @ if negative, don't use
23 STO 02
24 Y↑X
25 ÷           @ reduce argument
26 ENTER
27 ENTER
28 EDIT        @ add the identity matrix directly
29 ↑
30▸LBL 01
31 ↓
32 RCL+ 01
33 →
34 FC? 77
35 GTO 01
36 EXITALL
37 1ᴇ-16        @ convergence crtiteria
38 STO 01
39 R↓
40▸LBL 02       @ main iteration 
41 X<>Y
42 RCL÷ 00
43 ISG 00
44 NOP
45 RCL× ST Z
46 X<>Y
47 RCL+ ST Y
48 DSE 03
49 GTO 02
50 STO- ST L
51 LASTX
52 RNRM
53 RCL- 01
54 R↓
55 0<? ST T       @ convergence test
56 GTO 02         @ repeat
57 0=? 02         @ skip if no argument reduction
58 GTO 04
59▸LBL 03         @ argument back squaring
60 STO× ST X
61 DSE 02
62 GTO 03
63▸LBL 04
64 FNRM           @ check for /force "out of Range" error on DM42  v. Free 3.0.15
65 LASTX          @ delete line 64,65 for later revisions
66 END

Best regards
Gjermund
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: (DM42) Matrix exponential - Gil - 08-11-2023, 11:46 PM
RE: (DM42) Matrix exponential - Gil - 08-12-2023, 10:01 AM
RE: (DM42) Matrix exponential - Gil - 08-12-2023, 08:26 PM
RE: (DM42) Matrix exponential - Gil - 08-12-2023, 08:55 PM
RE: (DM42) Matrix exponential - Gil - 08-13-2023, 10:51 AM
RE: (DM42) Matrix exponential - Gjermund Skailand - 08-13-2023 09:41 PM
RE: (DM42) Matrix exponential - Gil - 08-13-2023, 09:46 PM
RE: (DM42) Matrix exponential - Gil - 08-15-2023, 11:42 PM
RE: (DM42) Matrix exponential - John Keith - 08-16-2023, 12:01 PM
RE: (DM42) Matrix exponential - Gil - 08-16-2023, 12:45 PM
RE: (DM42) Matrix exponential - Werner - 08-23-2023, 07:16 AM
RE: (DM42) Matrix exponential - John Keith - 08-27-2023, 04:46 PM
RE: (DM42) Matrix exponential - Gil - 08-23-2023, 09:09 AM
RE: (DM42) Matrix exponential - Werner - 08-24-2023, 01:14 PM
RE: (DM42) Matrix exponential - Gil - 08-28-2023, 08:57 AM



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