#OK to post homework #Zidong Zhang, 14/2/2021, Assignment 7 #DrawMandelbrot(R,K):that plots the Mandelbrot set by picking all those complex c (of the #form x+I*y, with x,y in [-4,4] with resolution 1/R, and deciding whether to accept it if #iterating z goes to z^2+c (starting at z=0) after K iterations stay bounded. Also send the #output as .jpeg file, for R as large as possible. ###I don't know what's wrong with my code, it seems that actually generated a set of good ####point but it doesn't plot anything. DrawMandelbrot := proc(R,K) local f,x,y,z,c,s,X,Y,S,flag,i: S:=[]: X :=[seq(-4+i/R, i =0..8*R)]: Y :=[seq(-4+i/R, i =0..8*R)]: #c:= x + y*I: z:=0: f:=(z,c)->evalf(evalc(z^2 + c)): flag:=0: for x in X do for y in Y do c:= x + y*I: for i from 1 to K do z:=f(z,c): if evalf(Re(z)^2+Im(z)^2)>4 then flag:= 1: fi: od: if flag=0 then S:=[op(S),[Im[c],Re(c)]]: else continue: fi: z:=0: flag :=0: od: od: plot(S): #S: end: ###I don't know what's wrong with my code, it seems that actually generated a set of good ####point but it doesn't plot anything. #RandSPn(n):that inputs a positive integer n and outputs a (uniformly) at random set #partition of {1,...,n} RandSPn := proc(n) local k: {seq(op(RandSPnk(n,k)),k=1..n)}: end: #NuAdjacentMates(SP,n):that inputs a set partition, SP, of {1, ...n}, and outputs the number #of i between 1 and n such that i and i+1 are part-mates NuAdjacentMates := proc(SP,n) local i,c,j: c:=0: for j from 1 to nops(SP) do for i from 1 to n do #for j from 1 to nops(SP) do if (is({i, i+1} subset SP[j]) = true) then c := c+1: fi: od: od: c: end: #EstimateAvAdjacentMates(n,K):that uses the above procedure, and your RandSPn(n), K #times, to estimate the average of the number of adjacent mates in a random set partition #of {1,...n}. EstimateAvAdjacentMates := proc(n,K) local C,N,i: C:=0: for i from 1 to K do N:=NuAdjacentMates(RandSPn(n),n): C:=C+N: od: C/K: end: ###the code is working but it took so long time without ending for n= 100. ###but it work for EstimateAvAdjacentMates(10,1000), which are 11041/500 , 11083/500 , ### 441/20 , 881/40, 22047/1000