(42S) Matrix Integer Powers
|
02-15-2015, 07:35 AM
(This post was last modified: 06-15-2017 01:48 PM by Gene.)
Post: #1
|
|||
|
|||
(42S) Matrix Integer Powers
A surprising omission on the 42S is the lack of a matrix powering function.
These two programmes supply the lack. IDN for positive integer input returns the identity matrix of input dimension. 0. { 26-Byte Prgm } 1. LBL “IDN” 2. ENTER 3. NEWMAT 4. EDIT 5. LBL 00 6. SIGN 7. → 8. FC? 76 9. ↓ 10. FC? 76 11. GTO 00 12. EXITALL 13. END For stack Y: Matrix X: Integer MAT↑ returns the input matrix to input power. 0. { 61-Byte Prgm } 1. LBL “MAT↑” 2. X>0? 3. GTO 03 4. X<>Y 5. INVRT 6. X<>Y 7. ABS 8. LBL 03 9. STO 02 10. X<>Y 11. ENTER 12. DIM? 13. R↓ 14. XEQ “IDN” 15. GTO 00 16. LBL 01 17. 2 18. MOD 19. X≠0? 20. GTO 02 21. LASTX 22. STO/ 02 23. R↑ 24. RCL* ST X 25. R↑ 26. RCL 02 27. GTO 01 28. LBL 02 29. STO- 02 30. R↓ 31. RCL* ST Y 32. LBL 00 33. RCL 02 34. X≠0? 35. GTO 01 36. R↓ 37. END |
|||
08-04-2023, 02:45 PM
Post: #2
|
|||
|
|||
RE: (42S) Matrix Integer Powers
All in the stack, integrated IDN, and avoiding a multiplication by the unit matrix:
Code: 00 { 66-Byte Prgm } Cheers, Werner 41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE |
|||
08-05-2023, 03:22 PM
Post: #3
|
|||
|
|||
RE: (42S) Matrix Integer Powers
Very nicely done - & you forgot to say significantly faster. Bravo!
|
|||
08-06-2023, 08:02 AM
Post: #4
|
|||
|
|||
RE: (42S) Matrix Integer Powers
Actually, in this case I merely reworked your programs:
- I used your IDN, with shorter tests - the exit test needs only to be performed when FP(n/2)=0, which was not the case in my original version ;-) Cheers, Werner 41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)