Engineering Math - Quick Reference                                 Home : www.sharetechnote.com

 

 

 

Chaos - Barnsley Fern

 

Description/Explanation will come later.

 

 

    m1 = [0.85 0.04;-0.04 0.85]; v1 = [0.0;1.60];

    m2 = [0.2 -0.26;0.23 0.22]; v2 = [0.0;1.60];

    m3 = [-0.15 0.28;0.26 0.24]; v3 = [0.0;0.44];

    m4 = [0.0 0.0;0.0 0.16]; v4 = [0.0;0.0];

     

    prob = [0.85 0.07 0.07 0.01];

     

    Np = 50000;

     

    p_old = [0.5;0.5];

     

    pList = [p_old'];

     

    for i = 1:Np

        r = rand();

        if (r < prob(1))

           p_new = m1 * p_old + v1;

        elseif (r < (prob(1)+prob(2)))

           p_new = m2 * p_old + v2;

        elseif (r < (prob(1)+prob(2)+prob(3)))

           p_new = m3 * p_old + v3;

        else

           p_new = m4 * p_old + v4;

        endif;

        pList = [pList;p_new'];

        p_old = p_new;

    end;

Note : the syntax of if statement of Octave may be a little different from Matlab. I tried this only on Octave, so not sure if this code would work in matlab.