41Z Routine of the Week: Complex Fibonacci
07-23-2020, 11:32 AM (This post was last modified: 07-25-2020 09:41 AM by Ángel Martin.)
Post: #1
 Ángel Martin Senior Member Posts: 1,368 Joined: Dec 2013
41Z Routine of the Week: Complex Fibonacci
Complex Fibonacci Numbers

The routine below uses the Binet formula with real orders "x" to obtain the Complex Fibonacci numbers. For integer inputs you should get the known Fibonacci series, but it gets interesting when you use non-integer values for the input.

This link shows graphs of the function output values in a couple of cases.

Input: x in the X register.

The program listing is below, step #4 PHI is the golden ratio, ~1.6108339887...

Code:
01  LBL "ZFIB"  superseded by version below 17  END
07-23-2020, 08:00 PM
Post: #2
 JMBaillard Junior Member Posts: 27 Joined: Dec 2013
RE: 41Z Routine of the Week: Complex Fibonacci
Hi Angel,

Thank you for your program.
Here is a focal version for complex arguments:

01 LBL "FIBZ"
02 STO 01
03 X<>Y
04 STO 02
05 CHS
06 PI
07 ST* Z
08 *
09 RCL Y
10 RCL Y
11 E^X
12 RAD
13 P-R
14 R^
15 CHS
16 R^
17 CHS
18 E^X
19 P-R
20 X<>Y
21 ST+ T
22 RDN
23 +
24 2
25 ST/ Z
26 /
27 R-P
28 STO 03
29 X<>Y
30 STO 04
31 5
32 SQRT
33 1
34 +
35 2
36 /
37 STO 00
38 LN
39 RCL 02
40 *
41 ST- 04
42 RCL 00
43 RCL 01
44 Y^X
45 ST/ 03
46 P-R
47 RCL 04
48 RCL 03
49 P-R
50 X<>Y
51 ST- T
52 RDN
53 -
54 5
55 SQRT
56 ST/ Z
57 /
58 DEG
59 END

( 77 bytes / SIZE 005 )

Y=y >>> Y'=v
X=x >>> X'=u with Fib(x+i.y) = u+i.v

Example:

.4 ENTER^
.3 XEQ "FIBZ" >>>> 0.179726826 ( 5 seconds )
X<>Y 0.677764999

Fib(0.3+0.4 i) ~ 0.179726826 + 0.677764999 i

Best regards.
07-25-2020, 09:11 AM (This post was last modified: 05-14-2021 11:54 AM by Ángel Martin.)
Post: #3
 Ángel Martin Senior Member Posts: 1,368 Joined: Dec 2013
RE: 41Z Routine of the Week: Complex Fibonacci
Very nice JM, thanks for your contribution.

here's the 41Z version to use for complex orders - which requires a modified Binet formula using an interesting correction term:

input is the complex order z in {Y, X}
41 bytes / SIZE 000

Code:
01 LBL "ZFIB" 02  ZRPL^ 03  PHI 04  X^Z    05  ZENTER^ 06  ZINV 07  ZRUP 08  PI 09  ST*  Z 10  * 11  ZCOS 12  Z* 13  Z- 14  5 15  SQRT 16  ST/  Z 17  / 18  ZAVIEW 19  END

Example: Fi(3+4i) ~ -5,248.511-J14,195.962

Cheers,
ÁM
 « Next Oldest | Next Newest »

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