Fractals from IFS and MRCM

2. If you haven't formed your transformations yet, you need to figure them out. The easy way to do that is to form the matrix A as follows:

A = [0 1 1; 0 0 1; 0 0 1]which represents the 3 corners of the square (0,0), (1,0), (1,1). Then for each quadrilateral, form the matrix B as follows:

B = [x1 x2 x3; y1 y2 y3; 0 0 1]where you put the coordinates you found for the corners in for the values (x1,y1), (x2,y2), (x3,y3). Then to find the transformation you just solve XA = B for the transformation X, by

3. Now you have your transformations, so create a M-file called
**mytrans.m** which contains them. The format should be like
this, with the names of transformations T{1}, T{2}, etc.

T{1} = [1/2 0 0;0 1/2 0;0 0 1]; T{2} = [1/2 0 1/2;0 1/2 0;0 0 1]; T{3} = [1/2 0 1/4;0 1/2 sqrt(3)/4;0 0 1];Next, copy these 2 functions into the M-file editor and save them:

**mrcm.m**

function mrcm(pts,N,T) % routine for MRCM (multiple reduction copy machine) % pauses between iterations, starts with any image % an applies the various transformations in N cycles k = length(T); % number of transformations np = [pts; ones(1,size(pts,1))]; % copy of points (homog) plot(np(1,:),np(2,:)) axis equal, axis off pause for i = 1:N xp = []; for j = 1:k p = T{j}*np; % apply transformation xp = [xp [NaN NaN 1]', p]; % add image to other copies end np = xp; plot(np(1,:),np(2,:)) axis equal, axis off pause end

function ifs(N,T) % does N iterations of the IFS defined % by the transformations passed in K = length(T); % number of transformations X = zeros(3,N); % allocate space X(:,1) = [0.5; 0.5; 1]; % starting point for i = 1:N-1 r = floor(K*rand)+1; % random number in 1..K X(:,i+1) = T{r}*X(:,i); end plot(X(1,:),X(2,:),'.','MarkerSize',1) axis off

image = [0 0; 1 0; 1 1; 0 1; 0 0]';Next you need your transformations, so just type

mrcm(image,4,T)where 4 is the number of levels you want it to run (you shouldn't try a level more than 6 or 7 as MATLAB may crash. The function pauses after each iteration, so you need to hit the space bar to get it to continue. If you want it to stop, type ctrl-C.

ifs(1000,T)where 1000 is the number of points you want it to plot. You should increase the number of points to about 100000 to see the fine details.

2. Pick on of the transformations below and try either MRCM or IFS with them. Again produce a printout.

Turn in your 3 pictures and the file containing the transformations that you created.

clear T T{1} = [0 0 0; 0 0.16 0; 0 0 1]; T{2} = [0.85 0.04 0; -0.04 0.85 1.6; 0 0 1]; T{3} = [0.2 -0.26 0; 0.23 0.22 1.6; 0 0 1]; T{4} = [-0.15 0.28 0; 0.26 0.24 0.44; 0 0 1];

clear T T{1} = [0 0 0; 0 0.5 0;0 0 1]; T{2} = [0.42 -0.42 0; 0.42 0.42 0.2;0 0 1]; T{3} = [0.42 0.42 0; -0.42 0.42 0.2; 0 0 1]; T{4} = [0.1 0 0; 0 0.1 0.2; 0 0 1];

clear T T{1} = [1/3 0 0; 0 1/3 0; 0 0 1]; T{2} = [1/3*cos(pi/3) -1/3*sin(pi/3) 1/3; 1/3*sin(pi/3) 1/3*cos(pi/3) 0; 0 0 1]; T{3} = [1/3*cos(pi/3) 1/3*sin(pi/3) 1/2; -1/3*sin(pi/3) 1/3*cos(pi/3) sqrt(3)/6; 0 0 1]; T{4} = [1/3 0 2/3; 0 1/3 0; 0 0 1];

clear T T{1} = [1/2 0 0;0 1/2 0;0 0 1]; T{2} = [1/2 0 1/2;0 1/2 1/2; 0 0 1]; T{3} = [1/2 0 1/2; 0 1/2 0; 0 0 1];

clear T T{1} = [1/3 0 0; 0 1/3 0; 0 0 1]; T{2} = [1/3 0 2/3; 0 1/3 0; 0 0 1]; T{3} = [1/3 0 1/3; 0 1/3 1/3; 0 0 1]; T{4} = [1/3 0 0; 0 1/3 2/3; 0 0 1]; T{5} = [1/3 0 2/3; 0 1/3 2/3; 0 0 1];

clear T T{1} = [1/3 0 0;0 1/3 0;0 0 1]; T{2} = [1/3 0 1/3;0 1/3 0; 0 0 1]; T{3} = [1/3 0 2/3;0 1/3 0; 0 0 1]; T{4} = [1/3 0 0;0 1/3 1/3; 0 0 1]; T{5} = [1/3 0 2/3;0 1/3 1/3; 0 0 1]; T{6} = [1/3 0 0;0 1/3 2/3;0 0 1]; T{7} = [1/3 0 1/3;0 1/3 2/3;0 0 1]; T{9} = [1/3 0 2/3;0 1/3 2/3;0 0 1];

clear T R = [0 -1 0;1 0 0; 0 0 1]; % 90 degree rot T{1} = [1/2 0 1/2; 0 1/2 0;0 0 1]*R; T{2} = [1/2 0 1/2;0 1/2 1/2;0 0 1]*inv(R); T{3} = [1/2 0 1/4;0 1/2 sqrt(3)/4;0 0 1];

clear T R = [0 1 0;-1 0 0; 0 0 1]; % 270 degree rot T{1} = [2/3 0 0;0 2/3 2/3;0 0 1]*R; T{2} = [2/3 0 0;0 2/3 1;0 0 1]*R; T{3} = [2/3 0 1/3;0 2/3 5/6;0 0 1]*R;

clear T R = [0 -1 0;1 0 0;0 0 1]; % 90 degree rot T{1} = [1/3 0 1/3;0 1 0;0 0 1]*R; T{2} = [1/3 0 1/3;0 1/3 2/3;0 0 1]; T{3} = [1/3 0 2/3;0 1 0;0 0 1]*[-1 0 0;0 1 0;0 0 1]*R;Mail: ccollins@math.utk.edu