Maple Text Commands for Chapter 15 -
FRACTALS AND MULTIFRACTALS
Figure 15.2: The Koch curve.
| > | restart:with(plots):
segmnt:=array(0..100000): x:=array(0..100000):y:=array(0..100000): k:=6: # Construction up to stage k. mmax:=4^k: h:=3^(-k): x[0]:=0:y[0]:=0: # Initial point. angle(0):=0:angle(1):=Pi/3: angle(2):=-Pi/3:angle(3):=0: # Angles of the 4 segments. for i from 0 to mmax do m:=i:ang:=0: for j from 0 to k-1 do segmnt[j]:=m mod 4: # Work with numbers modulo 4. m:=iquo(m,4): ang:=ang+angle(segmnt[j]):end do: x[i+1]:=evalf(x[i]+h*cos(ang)): # Define the (i+1)'st segment. y[i+1]:=evalf(y[i]+h*sin(ang)):end do: j:='j': pts:=[[x[j],y[j]] $j=0..mmax]: plot(pts,color=blue,axes=NONE,scaling=CONSTRAINED); |
![]() |
Figure 15.3: The Koch square.
| > | with(plots):
segmnt:=array(0..100000): x:=array(0..100000):y:=array(0..100000): k:=6:mmax:=5^k: # Each segment is replaced with 5 segments. h:=3^(-k): x[0]:=0:y[0]:=0: angle(0):=0:angle(1):=Pi/2:angle(2):=0: angle(3):=-Pi/2:angle(4):=0: # Angles of the 5 segments. for i from 0 to mmax do m:=i:ang:=0: for j from 0 to k-1 do segmnt[j]:=m mod 5: m:=iquo(m,5): ang:=ang+angle(segmnt[j]):end do: x[i+1]:=evalf(x[i]+h*cos(ang)):y[i+1]:=evalf(y[i]+h*sin(ang)):end do: i:='i':j:='j':k:='k':l:='l': # Rotate and translate to get 4 edges. pts1:=[[x[i],-y[i]] $i=0..mmax]:pts2:=[[x[j],y[j]+1] $j=0..mmax]: pts3:=[[x[k]*cos(-Pi/2)+y[k]*sin(-Pi/2),-x[k]*sin(-Pi/2)+y[k]*cos(-Pi/2)] $k=0..mmax]: pts4:=[[-(x[k]*cos(-Pi/2)+y[k]*sin(-Pi/2))+1,-x[k]*sin(-Pi/2)+y[k]*cos(-Pi/2)] $k=0..mmax]: p1:=plot(pts1,color=black,axes=NONE):p2:=plot(pts2,color=black,axes=NONE): p3:=plot(pts3,color=black,axes=NONE):p4:=plot(pts4,color=black,axes=NONE): display({p1,p2,p3,p4},scaling=CONSTRAINED,axes=NONE,title=`The Koch Square`); |
![]() |
Figure 15.6: The Sierpinski triangle generated by the chaos game.
| > | with(plots):
x:=array(0..100000): A:=[0,0]:B:=[4,0]:C:=[2,2*sqrt(3)]: # The vertices of the triangle. x[0]:=[2,1]: # An initial point inside the triangle. mmax:=10000:scale:=1/2: for i from 0 to mmax do die:=RandomTools[Generate](integer(range=1..6)); die(); if die() < 3 then x[i+1]:=evalf(x[i]+(B-x[i])*scale): elif die() < 5 then x[i+1]:=evalf(x[i]+(C-x[i])*scale): else x[i+1]:=evalf(x[i]+(A-x[i])*scale):end if:end do: m:='m':pts:=[[x[m]] $m=10..mmax]: plot(pts,style=point,symbol=point,color=red,axes=NONE); |
![]() |
Figure 15.7: Barnsley's Fern
Definition. An iterated function system (IFS) is a finite set T1,T2,T3,...,Tn, of affine linear transformations of the real plane, where
Tj(x,y)=(ax+by+c,ex+fy+g).
The basic rules are: (i) Create 2 or more affine linear transformations. (ii) Assign probabilities to each transformation.
(iii) Start with an initial point. (iv) Select a random transformation to get a second point. (v) Repeat the process.
| > | restart;
Nmax:=50000:PP:=array(0..1000000):PP[0]:=[0.5,0.5]: T:=proc(a,b,c,x,y):a*x+b*y+c:end: die:=rand(1..100): for j from 0 to Nmax do r:=die(): if r<5 then PP[j+1]:=[T(0,0,0,op(1,PP[j]),op(2,PP[j])),T(0,0.2,0,op(1,PP[j]),op(2,PP[j]))]: elif r<86 then PP[j+1]:=[T(0.85,0.05,0,op(1,PP[j]),op(2,PP[j])),T(-0.04,0.85,1.6,op(1,PP[j]),op(2,PP[j]))]: elif r<93 then PP[j+1]:=[T(0.2,-0.26,0,op(1,PP[j]),op(2,PP[j])),T(0.23,0.22,1.6,op(1,PP[j]),op(2,PP[j]))]: else PP[j+1]:=[T(-0.15,0.28,0,op(1,PP[j]),op(2,PP[j])),T(0.26,0.24,0.44,op(1,PP[j]),op(2,PP[j]))]:end if:end do: pts:=[PP[n]$n=1..Nmax]: with(plots): plot(pts,style=point,symbol=point,color=green,axes=NONE); |
![]() |
Grid generation for box counting.
| > | with(plots):
hor:=array(0..10000):vert:=array(0..10000): # hor is horizontal. plothor:=array(0..10000):plotvert:=array(0..10000): # vert is vertical. l:=1/5: # l is the box-length. xmin:=-2:xmax:=2:ymin:=-2:ymax:=2: xrange:=(xmax-xmin): n:=xrange*(1/l): for i from 0 to n do hor[i]:=[[xmin,ymin+i*l],[xmax,ymin+i*l]]: vert[i]:=[[xmin+i*l,ymin],[xmin+i*l,ymax]]: plothor[i]:=plot(hor[i],axes=NONE,color=black): plotvert[i]:=plot(vert[i],axes=NONE,color=black):end do: display({plothor[m],plotvert[m]} $m=0..n,scaling=CONSTRAINED); |
![]() |
Figure 15.15(a): The
curve.
| > | with(plots):
p1:=1/3:p2:=2/3:tau:=(ln(p1^x+p2^x))/(ln(3)): plot(tau,x=-5..5,labels=[`q`,`tau(q)`]); |
![]() |
Figure 15.15(b):
| > | Dq1:=(tau/(1-x)):D1:=plot(Dq1,x=-20..0.9999):D2:=plot(Dq1,x=1.0001..20):
display({D1,D2},axes=BOXED,labels=[`q`,`Dq`]); |
![]() |
Figure 15.15(c): The
spectrum.
| > | with(plots):
k:=500:p1:=1/3:p2:=2/3: plot([(t*ln(p1)+(k-t)*ln(p2))/(k*ln(1/3)),-(ln(binomial(k,t)))/(k*ln(1/3)),t=0..500],labels=[`alpha`,`f(alpha)`]); |
![]() |
End of Chapter 15 Commands