Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

The code below is an attempt to use more than one generator (in this case two) to generate a fractal using the standard iterative procedure involving generators. Only the first two stages of the construction are included. Ideally, for each line segment one of the two generators would be applied selected at random. This would be similar to Mandelbrot's stock chart cartoons including what he called shuffling. An y help with streamlining the code would be aoppreciated

 {a1, b1} = {.3, .6}; {a2, b2} = {.7, .2};
{c1, d1} = {.2, .7}; {c2, d2} = {.6, .3};
Clear[y1, f1, g1, h1, i1, j1, k1];
Clear[y2, f2, g2, h2, i2, j2, k2];
y0[x_] := x;
If[RandomInteger[] == 1,
 f1[x_] := b1*y0[x*1/a1];
 g1[x_] := (b2 - b1)*y0[(x - a1)/(a2 - a1)] + b1;
 h1[x_] := (1 - b2)*y0[(x - a2)/(1 - a2)] + b2;
 y1[x_] /; 0 <= x < a1 := f1[x];
 y1[x_] /; a1 <= x < a2 := g1[x];
 y1[x_] := h1[x],

 i1[x_] := d1*y0[x*1/c1];
 j1[x_] := (d2 - d1)*y0[(x - c1)/(c2 - c1)] + d1;
 k1[x_] := (1 - d2)*y0[(x - c2)/(1 - c2)] + d2;
 y1[x_] /; 0 <= x < c1 := i1[x];
 y1[x_] /; c1 <= x < c2 := j1[x];
 y1[x_] := k1[x]]


If[RandomInteger[] == 1,
 f2[x_] := b1*y1[x*1/a1];
 g2[x_] := (b2 - b1)*y1[(x - a1)/(a2 - a1)] + b1;
 h2[x_] := (1 - b2)*y1[(x - a2)/(1 - a2)] + b2;
 y2[x_] /; 0 <= x < a1 := f2[x];
 y2[x_] /; a1 <= x < a2 := g2[x];
 y2[x_] := h2[x],

 i2[x_] := d1*y1[x*1/c1];
 j2[x_] := (d2 - d1)*y1[(x - c1)/(c2 - c1)] + d1;
 k2[x_] := (1 - d2)*y1[(x - c2)/(1 - c2)] + d2;
 y2[x_] /; 0 <= x < c1 := i2[x];
 y2[x_] /; c1 <= x < c2 := j2[x];
 y2[x_] := k2[x]]

Plot[y1[x], {x, 0, 1}, PlotRange -> {{0, 1}, {0, 1}}]
Plot[y2[x], {x, 0, 1}, PlotRange -> {{0, 1}, {0, 1}}]
share|improve this question

1 Answer 1

Here's an iterated function system that implements Barnesley's fractal fern, which can be generated by four linear systems, chosen randomly with probabilities p1, p2, p3 and p4.

a1 = {{0, 0}, {0, 0.16}}; b1 = {0, 0}; p1 = 0.01;
a2 = {{0.85, 0.04}, {-0.04, 0.85}}; b2 = {0, 1.6}; p2 = 0.85;
a3 = {{0.2, -0.26}, {0.23, 0.22}}; b3 = {0, 1.6}; p3 = 0.07;
a4 = {{-0.15, 0.28}, {0.26, 0.24}}; b4 = {0, 0.44}; p4 = 0.07; 
ListPlot[
 NestList[RandomChoice[{p1, p2, p3, p4} -> {a1.# + b1, a2.# + b2, 
      a3.# + b3, a4.# + b4}] &, {0.5, 0.5}, 50000], 
 PlotRange -> {{-6, 6}, {0, 12}}, AspectRatio -> 1, Axes -> False, 
 ColorFunction -> Hue[x], PlotStyle -> AbsolutePointSize[1]]

enter image description here

At each iteration, one of the four linear systems (defined by the four a's and b's) is chosen and the point bounces to the location specified by a.x+b. The collection of all such points generates the fern. Changing the coefficients changes the shape, changing the number of iterations changes the amount of detail. Now that I have answered, I notice that there are also good answers to this problem at this question.

share|improve this answer
    
Thanks bill s. I am familiar with general IFS. What I'm trying to do is V-Variable Fractal Interpolation Functions which combines more than one IFS along with fractal interpolation. The process generates a sequences of functions that converges to the fractal interpolation function. I'm looking for code that does exactly what the code I posted in the question does, only more efficiently. –  Jon Jul 19 at 2:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.