Anzeige
2) A fractal is a curve or geometric figure comprised of a pattern tha.docx
2) A fractal is a curve or geometric figure comprised of a pattern tha.docx
Nächste SlideShare
3D Math Primer: CocoaConf Atlanta3D Math Primer: CocoaConf Atlanta
Wird geladen in ... 3
1 von 2
Anzeige

Más contenido relacionado

Más de lcarolyn(20)

Anzeige

2) A fractal is a curve or geometric figure comprised of a pattern tha.docx

  1. 2) A fractal is a curve or geometric figure comprised of a pattern that repeats at every scale. One approach to generating a fractal is called a chaos game. A chaos game is an algorithm in which points are plotted iteratively according to small set of rules. After a sufficient number of points are plotted, a pattern emerges. A section of the boundary of the Dragon Curve fractal can be plotted in MATLAB using the chaos game approach by plotting points iteratively according to one of the following three rules that are selected randomly with equal probability. (You will need to look up the randi function.) Write a MATLAB script that calculates the x and y vectors, then plots x vs y using plot(x,y,'.r'). Start with x1 = 0 and y1 = 1. Perform 50000 iterations. Hint 1: At each iteration you'll calculate a new x and y from the old x and y. Which rule you use to calculate the new x and y is determined by ''flipping a coin'' (randi). This coin flip happens every iteration. Solution Matlab Code: x(1)=0; y(1)=1; % Initially setting x=0;y=1 for i=1:50000 % looping from 1 to 50000 p=randi(3); % Generating a random number 1,2 or 3 will be generated if p==1 % Initially i=1 will be selected and it will check whether randi() generated 1,2 or 3. x(i+1)=((x(i)-y(i))/4)-(1/2); % if randi(3) generated 1 it will come to this line y(i+1)=((x(i)+y(i))/4)+1; else if p==2 % if randi(3) generated 2 it will execute this loop x(i+1)=((y(i)-x(i))/4)+(1/2); y(i+1)=-((x(i)+y(i))/4)+1; else if p==3 % if randi(3) generated 3 it will execute this loop and will generate x,y from previous values x(i+1)=((x(i)+y(i))/2)+1; y(i+1)=((y(i)-x(i))/2); end end end end % In this way we get a vector of x,y values and now we plot them plot(x,y,'.r')
Anzeige