How to generate numbers from the Fibonacci Sequence?

Apr 22, 2011 at 5:36pm

How to generate numbers from the Fibonacci Sequence?

hey i’m trying to create a composition with midi, at the moment ive managed to figure out how to generate random numbers but i wanted to make it generate numbers from the Fibonacci sequence, is this possible and how would i go about programming it to do this?

thanks

#56515
Apr 22, 2011 at 7:15pm

I would put numbers from the Fibonacci sequence in a coll or table, and select them randomly.

#202629
Apr 22, 2011 at 8:02pm

Two immortal rabbits + single malt scotch and just let nature take its course

#202630
Apr 22, 2011 at 8:03pm

okay thank you! how do i go about putting in a coll or table into my patcher – sorry i am very new to max msp

#202631
Apr 22, 2011 at 10:27pm

Please examine carefully the used objects by alt-clicking them (open helpfile) to see how they work…
hth o

– Pasted Max Patch, click to expand. –
#202632
Apr 23, 2011 at 1:56am

As long as I’m already musing about the fact that pedagogy and pedantic have the same root, I might as well post this improvement to the patch above (my changes noted in red):

– Pasted Max Patch, click to expand. –

If you’re wondering what to do with that text, look at this thread:

http://cycling74.com/forums/topic.php?id=26095

#202633
Apr 23, 2011 at 5:44am

   

Attachments:
  1. 110.fibonacci.zip
#202634
Apr 23, 2011 at 7:39am

@ Chris Muir: thanks for your improvement. I was not aware of the funnel and the listfunnel objects until today…

ole

#202635
Apr 23, 2011 at 8:24am

Thank you all! this has been a HUGE help!

is there a way to make it so the numbers play in a particular order that i choose or must it be done in random?

#202636
Apr 23, 2011 at 4:52pm

Hi
If you send [coll] a pair of numbers it stores the second value at the ‘first’ index; if you send [coll] individual numbers it outputs the value at that index, so sending [coll] ’2′ will output the value stored at index# 2. So, if you want values from indices 1, 2, 3, 6, 9 and 6, send it a stream made up of those numbers (not a list I think)….

@Chris pedagogue v pedant LOL niiiiice.
For the record, it’s really cool to see someone appending/varying/improving another’s patch, used to happen a lot here but not so much recently.

Brendan

#202637
Apr 23, 2011 at 5:09pm

what he said … plus some fixes.

#202638
Apr 25, 2011 at 3:53am

I became interested in ‘sacred geometry’ through music, and interested in general math through geometry, and programming through general math…so I’ve been meaning to do this for a while. It was one of the first things I tried to do when I started maxing a few months ago, but naturally I got the stack overflow message and quickly got discouraged.

I just found a workaround using messages, bangs and delays. This is just about my messiest patch yet, as I’m still fumbling for a more elegant method, and I opted for the old quick and dirty style. This is an actual fibonacci generator, rather than a preset list/recall function.

If you let it go long enough it starts to generate negative numbers (I’m not sure why, perhaps some cap on the length of message boxes?). It’s accurate to the 46th iteration, I think, but it breaks down after that.

If anyone knows why it does that, and can fix it, I’d be grateful. I’m on the right track, I think, but I lack the experience to troubleshoot beyond this. I’m sure the community could find uses for an an accurate fibonacci generator.

Est voila!

– Pasted Max Patch, click to expand. –
#202639
Apr 25, 2011 at 5:21am

Here’s how I generate random Fibonacci numbers in my patches:

– Pasted Max Patch, click to expand. –
#202640
Apr 25, 2011 at 8:06am

Ha!

Well that is certainly much simpler than my way, to say the least.

On a positive note, I’m learning more about using coll, and I think I’ve found a much better workaround to avoid stack overflows. Given some work I think I’m going to be able to bypass the 31 digit limit for other fractal numbers, with a little help from coll and some funky math. If it works I’ll post here.

Thanks for the benefit of your experience, Roth.

#202641
Apr 25, 2011 at 8:39am

Or you can use the formula for generating fibonacci numbers and then you don’t have to rely on your coll’s memory capacity to generate the numbers (or limit yourself to how many numbers you have inserted in the coll before you start):

– Pasted Max Patch, click to expand. –
#202642
Apr 25, 2011 at 10:39am

a 6th version anyone?

btw, finbonacci numbers are SO useless for music. ^^

#202643
Apr 25, 2011 at 4:50pm

All these Fibonacci generators are cool, but with only the first 45 numbers in the Fibonacci series fitting within the constraints of a Max integer, I think that the table approach is the best bet.

(and I do have a bucket-based Fibonacci generator somewhere)

#202644
Apr 25, 2011 at 8:08pm

@Chris~ I wish I’d known about bucket when I started, thanks.

@Roman~ The numbers get real big real fast, so I’d agree with you if it weren’t for the [%] object. Between that and [round] I can think of quite a few uses for spicing up some generative synths/random sequencers.

#202645
Apr 25, 2011 at 8:13pm

btw, finbonacci numbers are SO useless for music.

yeah so are major and minor scales. and chords.

#202646
Apr 25, 2011 at 9:23pm

It took a little digging, but I found my bucket-based version:

– Pasted Max Patch, click to expand. –
#202647
Apr 26, 2011 at 4:59am

How does it work?

#202648
Apr 26, 2011 at 6:23am

yeah, but my bucket version is greener than yours.

#202649
Apr 26, 2011 at 3:35pm

There’s a generator for Lucas Sequences in the CNMAT MMJ Depot, downloadable here: http://cnmat.berkeley.edu/downloads

Fibonacci numbers are a subset of that.

mz

http://en.wikipedia.org/wiki/Lucas_sequence

#202650
May 16, 2011 at 10:36am

I generated my own piece of JS for running Fibonacci and have hit upon an interesting Max query based upon the size of a list of numbers:

I can run the sequence up to ~150 values quite happily. I then decided to store a few variables in [coll]. Namely index, value, reciprocal. When I pack these three variables into a list, the value and reciprocal go AWOL at ~50th index.

As all three values use 32bit integers or floats, does the potential range of an int/float become limited when all are appended to the same list? i.e. does our 32bits get divided up between all list members?

Silly question this may be, but it’s something I’ve never considered before and perhaps is something to bear in mind when handling lists of large numbers in the future….

#202651
May 16, 2011 at 6:12pm

Max uses a signed 32 bit word, so the largest number is 2,147,483,647

#202652
May 17, 2011 at 10:16pm

Just wanted to say….

This is awesome love the thread

Fly Pro.

#202653

You must be logged in to reply to this topic.