Complex Cubic Equation  41Z Version Message #1 Posted by 聲gel Martin on 18 Oct 2011, 4:00 p.m.
Here's a corolary of this thread on solving the cubic equation using the trigonometric method.
http://www.hpmuseum.org/cgisys/cgiwrap/hpmuseum/archv020.cgi?read=180771#180771
It picked my curiosity and wanted to try it on the 41Z. The following programs are the result, amazingly short (around 65 zsteps) and showcasing the versatility of the machine.
Input: four complex coefs in Zstack four levels
Output: three roots in ZStack levels
Two versions, hyperbolic vs. circular functions.
Enjoy,
'AM
1 LBL "ZCRT" LBL "ZCRT"
2 ZRUP a3 ZRUP a3
3 Z/ a0/a3 Z/ a0/a3
4 ZSTO (00) a0' ZSTO (00) a0'
5 Z<>W a1 Z<>W a1
6 LASTZ a3 LASTZ a3
7 Z/ a1/a3 Z/ a1/a3
8 ZSTO 01 a1' ZSTO 01 a1'
9 ZRUP a'2 ZRUP a'2
10 LASTZ a3 LASTZ a3
11 Z/ a2/a3 Z/ a2/a3
16 3 3
17 ST/ Z ST/ Z
18 / /
19 ZSTO 02 a2' / 3 ZSTO 02 a2' / 3
12 Z^2 a2^2 / 9 Z^2 a2^2 / 9
13 3 3
14 ST* Z ST* Z
15 * a2^2/3 * a2^2/3
20 Z a1a2^2/3 Z a1a2^2/3
21 ZRCL 02 a2/3 ZRCL 02 a2 /3
22 Z^3 a2^3/27 Z^3 a2^3/27
23 ZDBL 2a2^3/27 ZDBL 2 a2^3/27
24 ZRCL 01 a1 ZRCL 01 a1
25 ZRCL 02 a2/3 ZRCL 02 a2/3
26 Z* a1*a2/3 Z* a1*a2/3
27 Z (a2^3/27)(a1*a2/3) Z (a2^3/27) (a1*a2/3)
28 ZRCL (00) a0 ZRCL (00) a0
29 Z+ q=a0+(a2^3/27)(a1*a2/ Z+ q = a0+(a2^3/27) (a1*a2/3)
30 ZHALF q/2 ZHALF q/2
31 Z<>W p Z<>W p
32 3 3
33 ST/ Z ST/ Z
34 / p/3 / p/3
35 Z/ 3q/2p Z/ 3q/2p
36 LASTZ p/3 LASTZ p/3
37 ZSQRT sqr(p/3) ZSQRT sqr(p/3)
38 ZSTO (00) ZSTO (00)
39 Z/ 3q/2p/sqr(p/3) Z/ 3q/2p / sqr(p/3)
40 ZHASIN ZASIN
41 3 3
42 ST/ Z ST/ Z
43 / 1/3 ash[ ] /
44 ZRPL^ ZRPL^
45 ,002 ,002
46 STO 02 STO 02
47 RDN RDN
48 LBL 02 LBL 02
49 RCL 02 RCL 02
50 INT INT
51 120 2kp/3 120 2kp/3
52 DR DR
53 * *
54 ST+ Z add to imaginary part + add to real part
55 RDN tidy up stack ZSIN
56 ZHSIN ZRCL (00)
57 ZRCL (00) Z*
58 Z* ZDBL
59 ZDBL ZRCL 02 a2/3
60 ZNEG Z
61 ZRCL 02 a2/3 ZAVIEW
62 Z ZRUP save in Zstack
63 ZAVIEW ISG 02
64 ZRUP save in Zstack GTO 02
65 ISG 02 END
66 GTO 02
67 END
Edited: 18 Oct 2011, 4:39 p.m.
