mandelbrot musing

mr_mapes's icon

Hey

In the long term I'll eventually be looking at using Mandelbrot/Julia sets in order to generate sound and synthesis but as a starting block and a general maths/max/programming muse I'm looking at how I can efficiently generate the set using Max objects...

I have a skeleton patch which performs a single iteration but the problem is in the feedback - the inevitable stack overflow that occurs when running stupid calculations with infinite feedback loops even when you have breakout conditions e.g. z>4 or n>100. I know I can use triggers and timing to solve the problem but in my eyes that defeats the point - I'd still like to run the routine waaay into 'the red' so to speak such that I can generate high resolution sets in the fastest allowable time...

Any thoughts?

andrea agostini's icon

Hard to say without seeing your patch...

Anyway, you get stack overflow if you feed your result back in a "hot" inlet. A strategy to avoid this can be to feed it in a "cold" inlet, and having an Uzi set to a large enough number triggering your computations one after another. The drawback of this solution is that you can't interrupt the shooting, and this can be quite time-consuming. But the point is, there is no such thing as easy-to-control iterations in Max.

A possible (although somewhat cumbersome) alternative is to use bach.iter with a long enough input list, instead of Uzi. bach lists can have virtually unlimited length, and bach.iter allows to stop the iteration "on the fly" - if you're curious, give a look at www.bachproject.net

But the truth is, the best you can do is writing some code - I'd say that, given the nature of the problem, even some JavaScript would give you better results than a patch. And if you feel like leaping to Java or C the results will be amazing, I promise!

good luck
aa

seejayjames's icon

I second that, I worked for a couple hours to make a prime factorization patch in Max, it works fine, but due to the iteration, at high enough numbers I get stack overflows. (Was pretty smooth up until 600000!)

I have a teensy javascript instead, which has never failed me, and lets me create factorizations and put them into a text file at 100 numbers per second, no problem. Wish I could do that in my head. Or maybe not...

Anyway, the advice is good, there are certain things you just don't want to iterate (recursively) at certain speeds in max.

ligiahag7902's icon

Thank you so much for your post.

__________________watch movies online free

mr_mapes's icon

Writing in C or Java would be a more elegent solution - writing objects in code is something I never covered at uni mind and have no notes about how to go about it... Guess I'll have to do some research!!

andrea agostini's icon

Really, try with JavaScript first. It's slow, but easier than Java and waaaay easier than C - and, once you've grasped the concepts, switching to another language will be relatively straightforward. There are some JavaScript tutorials in the Max doc to get you started, and tons of info around the net. You'll see that a basic implementation of a Mandelbrot calculator is quite simple to code.

have fun!!!
aa

mr_mapes's icon

Oh I have some experience in C, but never looked at Java. And I've coded a neat looking set in AS2 recently. I tried using [flashserver] to link my AS2 code with Max but it was pretty lethargic - wasn't running anywhere near as quick as I would've liked.

Likesay I think I just need to look up how to write Max objects in C :)

seejayjames's icon

AS2 and javascript should be pretty close, except for the Flash-specific methods of course.

Plenty of code samples online for making cool sets, you can adapt to js pretty easily. w3schools.com is great for all things web, and has a large section on js as well.

For a fun fractal overview, check this out...oh yeah!

mr_mapes's icon

Wicked - starting to get to grips with the javascripting - as helpful as the java tutorials are they talk little of handling multiple inlets but I got there in the end... Hopefully I'll have some max fractalness to post soon!

Nice one for the advice guys