Post Reply 
[VA] SRC #012b - Then and Now: Root
11-09-2022, 09:02 AM (This post was last modified: 11-10-2022 07:04 AM by Werner.)
Post: #4
RE: [VA] SRC #012b - Then and Now: Root
(error corrected in PX)
There are indeed no real roots.
I simply built the polynomial, stored its coefficients in a matrix P, and used my complex solver (explanation and source code here) with starting value 0 to find
(-0.645758096347,0.483177676217), abs value 0.806513599261

here's the polynomial generator routine:

00 { 139-Byte Prgm }
01▸LBL "PLST"
02 1
03 10001
04 NEWMAT
05 EDIT
06 1.001
07 STO 00
08 SIGN
09 STO IND 00
10 2
11 XEQ 14
12 3
13 XEQ 14
14 +
15 XEQ 14
16▸LBL 02
17 2
18 XEQ 03
19 FS? 77
20 GTO 00
21 4
22 XEQ 03
23 FC? 77
24 GTO 02
25▸LBL 00
26 RCLEL
27 EXITALL
28 STO "P"
29 RTN
30▸LBL 03
31 +
32 RCL 00
33 X<>Y
34▸LBL 04 @ ( loop over all stored primes )
35 RCL IND ST Y
36 RCL ST Y
37▸LBL 05 @ ( GCD )
38 MOD
39 LASTX
40 X<>Y
41 X>0?
42 GTO 05
43 +
44 R↓
45 DSE ST T @ ( test whether GCD=1 )
46 RTN
47 ISG ST Y
48 GTO 04
@ ( either the number is prime or it is a perfect square of one )
49 ENTER
50 SQRT
51 IP
52 X^2
53 X<>Y
54 X>Y? @ ( number is prime )
55 GTO 14
56 SQRT @ ( number is a perfect square )
57 STO IND ST Z @ ( store it in next register, just in case )
58 DSE ST Z @ ( will always skip )
59 X>0? @ ( nop )
60 RCL IND ST Z
61 ×
62 SIGN @ ( see if product is too large )
63 LASTX
64 STO+ ST Y
65 X=Y?
66 GTO 00
67 STO IND ST T @ ( if not, save it )
68 RCL ST Z
69 RTN
70▸LBL 00 @ ( else increase array )
71 1ᴇ-3
72 STO+ 00
73 R^
74 RTN
75▸LBL 14 @ ( separate label to easily change )
76 →
77 END


and the polynomial evaluator (coefficients [a0 a1 .. an] so Horner scheme has to start at the end)

00 { 25-Byte Prgm }
01▸LBL "PX" @ evaluate polynomial, matrix indexed at (1,1)
02 ENTER
03 ENTER
04 ENTER
05 CLX
06 J- @ start from the end
07▸LBL 02
08 ×
09 RCLEL
10 +
11 J-
12 FC? 77
13 GTO 02
14 J+ @ back to (1,1)
15 END


There is, however, a much better way, one that singles out the smallest root (thanks Albert!). Working on that ;-)
Cheers, Werner

41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: [VA] SRC #012b - Then and Now: Root - Werner - 11-09-2022 09:02 AM



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