#OK to post homework #Charles Kenney, March 15, 2020, Assignment 15 #1. The results of running NickAv(4,4,1.3,1.0,1000,10000,E,E,M) 10 times: #9.9328, 11.9492, 10.8632, 10.7632, 10.8384, #11.0156, 11.4548, 11.0688, 10.2564, 10.4040 #These results vary from one another a good amount. Could it be that #The algorithm is sensitive to the starting random matrix? #2. The results of running NickAv(40,40,1.3,1.0,1000,10000,E,E,M) 10 times: #822.9956, 909.2212, 860.5820, 864.0736, 888.7244, #875.4416, 883.7940, 936.1312, 906.6236, 868.9172 #In absolute terms, these results are even farther from one another than #the results for NickAv(4,4,...), but in relative terms they #are similarly spaced. #3. NickAvONE(M,N,x,y,K1,K2,G,En,Ma) is just like NickAv(...) #except that instead of inputting a random matrix, it starts with #a matrix of all 1s NickAvONE:=proc(M,N,x,y,K1,K2,G,En,Ma) local A,i,su,j: A:=[seq([seq(1,j=1..N)],i=1..M)]: for i from 1 to K1 do A:=OSM(A,M,N,x,y): od: su:=0: for i from 1 to K2 do A:=OSM(A,M,N,x,y): su:=su+subs({En=Ene(A),Ma=Mag(A)},G): od: evalf(su/K2): end: #Now the outputs from running NickAvONE(4,4,1.3,1.0,1000,10000,E,E,M) #ten times are: #10.3772, 10.9248, 9.8596, 11.4092, 10.1216, #11.0996, 10.7924, 10.7076, 10.7196, 11.8880 #These do not seem to be much more clustered than the outputs #which began with a random matrix. Curious! #Here are the outputs from running #NickAvONE(40,40,1.3,1.0,1000,10000,E,E,M) 10 times: #1372.4368, 1340.6256, 1351.5400, 1423.3656, 1369.7848, #1296.9268, 1309.1656, 1398.4184, 1448.8112, 1365.8460 #Again, the clustering is about the same as before. #NickAvALT(M,N,x,y,K1,K2,G,En,Ma) is just like NickAv(...) #except that instead of inputting a random matrix, it starts with #a matrix alternating +/- 1s NickAvALT:=proc(M,N,x,y,K1,K2,G,En,Ma) local A,i,su,j: A:=[seq([seq((-1)^(i+j),j=1..N)],i=1..M)]: for i from 1 to K1 do A:=OSM(A,M,N,x,y): od: su:=0: for i from 1 to K2 do A:=OSM(A,M,N,x,y): su:=su+subs({En=Ene(A),Ma=Mag(A)},G): od: evalf(su/K2): end: #The outputs from running NickAvALT(4,4,1.3,1.0,1000,10000,E,E,M) #ten times are: #10.7172, 10.6196, 10.0492, 10.4244, 11.0508, #10.8988, 10.6592, 10.0556, 10.3104, 11.6188 #And from NickAvALT(40,40,1.3,1.0,1000,10000,E,E,M): #807.4344, 838.7960, 869.7960, 873.6140, 871.3292, #892.9936, 810.8612, 871.3244, 824.1748, 852.0464 #4. Shrink(A) starts with a 3^k by 3^k matrix of {1,-1} #as always in a list of lists, and outputs #a 3^(k-1) by 3^(k-1) matrix according to majority rule. #First, we need a procedure that outputs a full list #of the neighbors of a point in a matrix (with no wrap-around, #for simplicity) #ThreeBy inputs a matrix A and a position c=[i,j], #outputs a list of the 9 nearest neighbors of c, #which form a 3x3 box centered at c. ThreeBy:=proc(A,c) local i,j: i:=c[1]: j:=c[2]: [A[i-1][j-1],A[i-1][j],A[i-1][j+1],A[i][j-1],A[i][j], A[i][j+1],A[i+1][j-1],A[i+1][j],A[i+1][j+1]]: end: #MajorRul inputs a {+1,-1} list of length 9, #outputs a 1 if a majority of entries are +1, #and a -1 otherwise MajorRul:=proc(L) local f: f:=add(L): if f>0 then 1: else -1: fi: end: Shrink:=proc(A) local i,j,k: k:=log[3](nops(A)): [seq([seq(MajorRul(ThreeBy(A,[3*j-1,3*i-1])),i=1..3^(k-1))],j=1..3^(k-1))]: end: