Wednesday, July 29, 2009

fractals

I got this book called 'chaos in wonderland' and decided to try out mathematica to create some of the fractals in the books. the fractals are 'dynamical systems' described by basically differential equations (x[n+1] can be thought of as a discrete form of dx) [1]

x[n+1] = sin(y[n]*a) + c*sin(y[n]*b)
y[n+1] = sin(x[n]*a) + d*sin(y[n]*b)

my first attempt at code

ListPlot[Table[
xn = N[Sin[y*b] + c*Sin[x*b]];
yn = N[Sin[x*a] + d*Sin[y*a]];
{x = xn, y = yn},
{i, 0, 10000}]]




this worked great. but to create a more functional style of iterated programming, I use the nestlist function which creates a list {x, f(x), f(f(x)), ...}, however instead of the one parameter 'x', I have parameters {x, y}. to deal with this I have to pass nested lists that I flatted at the end

Iter[list_] :=
{
{{x, y}} = list;
xn = N[Sin[y*b] + c*Sin[x*b]];
yn = N[Sin[x*a] + d*Sin[y*a]];
{xn, yn}
}

FSystemsPlot[l_, ax_, bx_, cx_, dx_] :=
{
a = ax; b = bx; c = cx; d = dx;
list = NestList[Iter, {{0.1, 0.1}}, 10000];
ListPlot[Flatten[list,1]]
}]


the book had a list interesting parameters for this system that created these graphs

http://img198.imageshack.us/g/image10jhh.png/

No comments:

Post a Comment