Tutorial 2.5

Generic ECE - University of Houston

Han Q. Le (c) Copyrighed

The objective of this tutorial to see how lists and arrays are used in common examples. Practice by creating your own similar example and have fun,

1. Multi-object personal data record

Exercise 1.5 Create a list of your personal data as shown below

If you have problem of recording with the microphone, chances are system doesn’t allow other apps to access the microphone. Google search how to allow apps access your microphone for your OS (e. g. Windows or Mac). Do same with camera.

mydatarec={"your last\! name","first name", "student ID" ,"email" (* all are String *)
,(* image object: your selfie obtained earlier with ImageCapture[] If you have no webcam, OK to put in your selfie from phone or other - Don't put in too big a file *)
, (* sound object: should be sound of you announcing your ID obtained above *)};

Answer (replace the below with your info - do at home)

The takeaways: the concept of data record and database structure.

Google search datarecord and database

2. Learn to import file: gif and graphics

Do the exercise in Tutorial_2_answer section 3.3, exercise 3.8. Make sure you have output gif file “emwave.gif” already on your laptop and bring the file to the class. Then, you will follow instructions what to do with it in class. This is what one frame of the file should look like:

2.1 Import file data as List

emwimp=Import["http://courses.egr.uh.edu/ECE/ECE3340/Class%20Notes/emwave.gif"] ;

Length[emwimp]

emwRev=Reverse @ emwimp;
Manipulate[
Show[emwRev[[i]]
,Graphics[{Hue[0.45,1,1]
,Rotate[
Rectangle[ImageScaled[{0.465,0.9}]
,ImageScaled[{0.535,1}]]
,(i-1)*2 π/Length[emwRev]]}]
,Graphics[{Text[Style["reverse",White,16,FontFamily->"Arial"]
,ImageScaled[{0.85,0.95}]]
}]]
,{i,1,Length[emwRev],1}]

2.2 Add/modify graphics

emwRev2=Table[
Show[emwRev[[i]]
,Graphics[{Hue[0.45,1,1]
,Rotate[
Rectangle[ImageScaled[{0.465,0.9}]
,ImageScaled[{0.535,1}]]
,(i-1)*2 π/Length[emwRev]]}]
,Graphics[{Text[Style["reverse",White,16,FontFamily->"Arial"]
,ImageScaled[{0.85,0.95}]]
}]]
,{i,1,Length[emwRev],1}];

Export["emwReverse.gif",emwRev2,"DisplayDurations"-> 0.025,AnimationRepetitions-> 100]

3. Exercise with list, array: sound

3.1 Make a tune

Given:

notes={"D5","D5","E5","D5","G5","F#5"
,"D5","D5","E5","D5","A5","G5"};
notedur=1/{8,16,4,4,4,2
,8,16,4,4,4,2};
tau=0.4;  beatdur=2. ; srate=11025;
tdur=notedur*beatdur; (* actual time duration of each note *)

Answer

notes={"D5","D5","E5","D5","G5","F#5"
,"D5","D5","E5","D5","A5","G5"};
notedur=1/{8,16,4,4,4,2
,8,16,4,4,4,2};
notefreqdata=Import["https://pages.mtu.edu/~suits/notefreqs.html","Data"][[2]];
freq=Table[Select[notefreqdata
,StringContainsQ[StringReplace[#[[1]]," "-> ""],n] & ][[1,2]]
,{n,notes}];
beatdur=2. ; srate=11025;Δt=1/srate;
tdur=notedur*beatdur; (* actual time duration of each note *)
tau=0.4; 
output=Flatten @ Table[Table[(E^(-t/tau)) Sin[2 π freq[[i]] t],{t,0.,tdur[[i]],Δt}],{i,Length[notes]}];
ListPlay[output, SampleRate->srate]

Export["HBtoyou.mp3",]

The takeaways: How to get and look up reference info, data.

3.2 Use function Map.

We can define a function to generate a sound signal. Then use Map to play from a list.

sndP[parm_]:=Table[(E^(-t/parm[[3]])) Sin[2 π parm[[1]]  t],{t,0.,parm[[2]],parm[[4]]}] ;
pdat=Transpose[{freq,tdur,ConstantArray[tau,Length[freq]],ConstantArray[Δt,Length[freq]]}];
outP=Flatten @ Map[sndP,pdat];  (* Map syntax is identical to Python  *)
ListPlay[outP, SampleRate->srate]

sndV[parm_]:=Table[(((1-(E^(-3*t/parm[[3]])))/(1+(E^(5*(t-0.9parm[[2]])/parm[[3]])))) ) 
(Sin[2 π parm[[1]]  t]
+0.2 Sin[2 π 0.5*parm[[1]]  t]
+0.4Sin[2 π 2 parm[[1]]  t]
+0.3Sin[2 π 3 parm[[1]]  t]),{t,0.,parm[[2]],parm[[4]]}] ;

pdat=Transpose[{freq,tdur,ConstantArray[tau,Length[freq]],ConstantArray[Δt,Length[freq]]}];outV=Flatten @ Map[sndV,pdat];
ListPlay[outV, SampleRate->srate]

Export["HBtoyou2.mp3",]

4. Exercise with list, array: illustration

See this graphics on the course webpage: social_media _market _share. A few students were able to do it couple years ago with less than one week intense-training on Mathematica that they had never learned before (but they were proficient in Python and programming in general). Do you think you can do it? Just write your thinking how you would go about to do something like it.

5. Exercise with list, array: graphics 1

to be done in class

Graphics3D[  Sphere[{0,0,0},1] ]

sphere1=Table[Sphere[{i,i,i},1],{i,10}] ;
Graphics3D[sphere1]

Manipulate[
sphere2=Table[Sphere[{i,i,i},r*i],{i,10}] ;
Graphics3D[sphere2]
,{r,0.1,1}
]

sphere3=Table[{Hue[(i/11.),0.7,1],Sphere[{i,0,0},0.5]},{i,10}] ;
Graphics3D[sphere3,Background->Black]

sphere4=Table[{Hue[(((10^2)(i-1)+10 (j-1) +k-1)/(9*(10^2)+9*10+10)),0.6,1],Sphere[{i,j,k},0.5]},{i,10}
,{j,10},{k,10}] ;
Graphics3D[sphere4,Background->Black]

cube1=Table[{Hue[(((10^2)(i-1)+10 (j-1) +k-1)/(9*(10^2)+9*10+10)),1,1]
,Cuboid[{i-0.4,j-0.4,k-0.4},{i+0.4,j+0.4,k+0.4}]},{i,10}
,{j,10},{k,10}] ;
Graphics3D[cube1,Background->Black]

The takeaways: Use indexed variables - as opposed to fixed numbers

6. Exercise with list, array: graphics 2 - animation

6.1 A spiral of spheres

nsph=12*16;  (* number of spheres *)
sphere5=Table[phi=Mod[s,12]*(π/6.);z=(s/12.); 
point5={z  ,2.*Cos[phi]  ,  2.*Sin[phi]};
{Hue[((s-1)/(nsph+1)),0.7,1],Sphere[point5,0.5]},{s,nsph}] ;
Graphics3D[sphere5 ,Background->Black ,ViewPoint-> {1,0,0}]

6.2 Animation with a time parameter

Manipulate[
Show[spiral,ViewVector->{ {t,0,0},{5,0,0}}
,ViewAngle-> 0.3
,Boxed->False
,Background-> Black]
,{t,-50,5}
,Initialization:>{
nsph=12*16;
sphere5=Table[phi=Mod[s,12]*(π/6.);z=(s/12.); 
point5={z  ,2.*Cos[phi]  ,  2.*Sin[phi]};
{Hue[((s-1)/(nsph+1)),0.7,1],Sphere[point5,0.5]},{s,nsph}] ;
spiral=Graphics3D[sphere5 ,Background->Black ]  ;

}]

gif generator

{nsph=12*16;
sphere5=Table[phi=Mod[s,12]*(π/6.);z=(s/12.); 
point5={z  ,2.*Cos[phi]  ,  2.*Sin[phi]};
{Hue[((s-1)/(nsph+1)),0.7,1],Sphere[point5,0.5]},{s,nsph}] ;
spiral=Graphics3D[sphere5 ,Background->Black ]  };
test1=Table[
Show[spiral,ViewVector->{ {t,0,0},{5,0,0}}
,ViewAngle-> 0.3
,Boxed->False
,Background-> Black]
,{t,-50,5,0.25}] ;

Export["spiralsph2.gif",test1,"DisplayDurations"-> 0.025,AnimationRepetitions-> 100]

Manipulate[
cube5=Graphics3D[{Hue[0.5,1,1,0.5]
,Cube[{2 π*t/50.,2 π*t/100}]},{25,0,0}];
Show[spiral,cube5,ViewVector->{ {t,0,0},{0,0,0}}
,ViewAngle-> 0.3
,Boxed->False
,Background-> Black]
,{t,-50,50}
,Initialization:>{
nsph=12*16;
sphere5=Table[phi=Mod[s,12]*(π/6.);z=(s/12.); 
point5={z  ,2.*Cos[phi]  ,  2.*Sin[phi]};
{Hue[((s-1)/(nsph+1)),0.7,1],Sphere[point5,0.5]},{s,nsph}] ;

spiral=Graphics3D[sphere5 ,Background->Black ]  ;
}]

gif generator

{nsph=12*16;
sphere5=Table[phi=Mod[s,12]*(π/6.);z=(s/12.); 
point5={z  ,2.*Cos[phi]  ,  2.*Sin[phi]};
{Hue[((s-1)/(nsph+1)),0.7,1],Sphere[point5,0.5]},{s,nsph}] ;
spiral=Graphics3D[sphere5 ,Background->Black ]  };
spircube=Table[
cube5=Graphics3D[{Hue[0.5,1,1,0.5]
,Cube[{2 π*t/50.,2 π*t/100}]},{25,0,0}];
Show[spiral,cube5,ViewVector->{ {t,0,0},{0,0,0}}
,ViewAngle-> 0.3
,Boxed->False
,Background-> Black] ,{t,-50,50,0.125}];

Export["spircube.gif",spircube,"DisplayDurations"-> 0.025,AnimationRepetitions-> 100]

Manipulate[
If[TrueQ[RANDsphGEN] || !TrueQ[nsphold== nsph],
rad=0.0025*RandomVariate[GammaDistribution[4,4],nsph];
pos=RandomReal[{-0.9,0.9},{nsph,3}];
nvect={Cos[#[[1]]]Cos[0.5*#[[2]]]
, Sin[#[[1]]]Cos[0.5*#[[2]]]
, Sin[0.5*#[[2]]]} & /@
RandomReal[{0,2π},{nsph,2}];
ϕsp=RandomReal[{-π,π},nsph];
hue=RandomReal[{0,1.},nsph];
RANDsphGEN=False; nsphold= nsph
,];
Show[Graphics3D[Table[{Hue[hue[[i]],1,1,0.6]
,Sphere[(Mod[#,2] -1.)&/@ (pos[[i]]+nvect[[i]]*t)
,rad[[i]]*(1+0.75Cos[2 π t*0.5+ϕsp[[i]] ])]},{i,nsph}]]
,PlotRange->{{-2,2},{-2,2}}
,Background->Black
,ImageSize->500]
,Button["generate",RANDsphGEN=True]
,{{nsph,100},{10,25,50,100,250}}
,{t,0,4}
,Initialization:>{
RANDsphGEN=True;
}]

gif generator

nsph=100;
rad=0.0025*RandomVariate[GammaDistribution[4,4],nsph];
pos=RandomReal[{-0.9,0.9},{nsph,3}];
nvect={Cos[#[[1]]]Cos[0.5*#[[2]]]
, Sin[#[[1]]]Cos[0.5*#[[2]]]
, Sin[0.5*#[[2]]]} & /@
RandomReal[{0,2π},{nsph,2}];
ϕsp=RandomReal[{-π,π},nsph];
hue=RandomReal[{0,1.},nsph];
sphereRandm=Table[
Show[Graphics3D[Table[{Hue[hue[[i]],1,1,0.6]
,Sphere[(Mod[#,2] -1.)&/@ (pos[[i]]+nvect[[i]]*t)
,rad[[i]]*(1+0.75Cos[2 π t*0.5+ϕsp[[i]] ])]},{i,nsph}]]
,PlotRange->{{-2,2},{-2,2}}
,Background->Black
,ImageSize->500]
,{t,0,4,0.025}
];

Export["sphereRandm.gif",sphereRandm,"DisplayDurations"-> 0.05,AnimationRepetitions-> 100]

The takeaways: Use indexed variables for animation, manipulation

Manipulate[

Show[cube1Gr,ViewVector->{flightC[t],flightC[t]+viewC[t]}
,ViewAngle-> 0.35
,Boxed->False
,Background-> Black]
,{t,-70,30}

,Initialization:>{
cube1=Table[{Hue[(({(10^2),10.,1} . {i-1,j-1 ,k-1})/1000.),1,1]
,Cuboid[{i,j,k}-0.4,{i,j,k}+0.4]},{i,10}
,{j,10},{k,10}] ;
cube1Gr=Graphics3D[{cube1,{White,Sphere[{5.5,5.5,50},3]}}
,Background->Black] ;
flightC[t_]:=If[t≤3.5,{5.5,t-2,3.5},If[t<7.5,{5.5,1.5+(Sqrt[16-(((t-7.5))^2)]),t},{5.5,5.5,t}]];
viewC[t_]:=If[t≤ 3.5,{0,1,0},If[t<7.5,{0,((7.5-t)/(Sqrt[16-(((t-7.5))^2)])),1} ,{0,0,1}]];

}]

gif generator

{cube1=Table[{Hue[(({(10^2),10.,1} . {i-1,j-1 ,k-1})/1000.),1,1]
,Cuboid[{i,j,k}-0.4,{i,j,k}+0.4]},{i,10}
,{j,10},{k,10}] ;
cube1Gr=Graphics3D[{cube1,{White,Sphere[{5.5,5.5,30},3]}}
,Background->Black] ;
flightC[t_]:=If[t≤ -10,{5.5,-12+(Sqrt[2]) (10+t),3.5-(Sqrt[2]) (10+t)}
,If[t≤3.5,{5.5,t-2,3.5},If[t<7.5,{5.5,1.5+(Sqrt[16-(((t-7.5))^2)]),t},{5.5,5.5,t}]]];
viewC[t_]:=If[t≤ -10,{5.5,5.5,10}-{5.5,-12+(Sqrt[2]) (10+t),3.5-(Sqrt[2]) (10+t)}
,If[t≤ 3.5,{0,1,0}
,If[t<7.5,{0,((7.5-t)/(Sqrt[16-(((t-7.5))^2)])),1} ,{0,0,1}]]];} ;
cubesphereflt=Table[
Show[cube1Gr,ViewVector->{flightC[t],flightC[t]+viewC[t]}
,ViewAngle-> 0.35
,Boxed->False
,Background-> Black]
,{t,-70,15,0.125}
];

Export["cubesphereflt.gif",cubesphereflt,"DisplayDurations"-> 0.005,AnimationRepetitions-> 100]

7. Exercise with list, array: graphics 3
Monte Carlo demo of Poisson distribution

7.1 Problem set up:

First, a description of the background.

https://www.youtube.com/watch?v=Sh1ZeWhAtRI

Exercise 7.1

Let’s assume that all the raindrops were lemondrops and gumdrops, and the kids all stood outside with mouths open wide. Assume that all the kids have mouth of the same size: 3-in diameter, what is the mouth area (in (inch^2))?

Answer

rmouth=1.5 inch;
aream=π * (((rmouth))^2)

or 7 (inch^2).

Exercise 7.2

Let the lemon/gumdrops density is 1 (lemon or gumdrop)/(inch^2) per 10 minutes. If we have 100 kids all stand outside with mouth open wide for 15 minutes, how many lemon or gumdrops would each kid catch? Wait, will everyone get exactly the same number of candies? No, some will get more, some will get less.
We should ask, what is the average number of candies that each kid can catch?

Answer

density=((1 lemongumdrop)/((inch^2) * 10 minutes)) ; time=15 minutes;
navecandies=density*aream*15 minutes

7.2 Monte Carlo simulation of a random process

The average is 10.6 candies.  But does that mean every kid would get exactly 10.6 lemon/gumdrops? If we count the number of “raindrops” each kids get, and tabulate on a histogram, do they all get 10, 11? or would some get 5, other would get 15 etc... Is it possible for some to get 20?

How do you answer the questions above. Or could it be that it doesn’t have an answer? If you have several groups of 10,000 kids each. Would there be any resemplance of their histograms? or will it be totally random for each group and all the histograms are different? 
In the follow, you should follow the guidelines to gain an understanding and see if you can answer those questions at the end.

7.2.1 Background

One way to study this problem is the Monte Carlo method:

7.2.2 Approach

We can use the computer to simulate 100 kids’ mouths and rain drops. First, set up the mouths:

Exercise 7.3

Let's make the mouth to be a circle (disk). Let' s assume the kids line up in 10 rows x 10 columns. Generate a graphics for the mouths, using Disk:

Manipulate[
Graphics[{Hue[0.08,0.3,1],Disk[{x,y},1.5]}
,PlotRange->{{0,20},{0,20}}]
,{x,1,19},{y,1,19}]

Answer

Grid[{{mouth=Graphics[{Hue[0.08,0.3,1],Table[Disk[3*{m,n}+{1.5,1.5},1.5],{m,0,9},{n,0,9}]}
,Background->Hue[0.65,1,0.4], ImageSize-> 400]
,Grid[ConstantArray[,{10,10}],Spacings-> {0.1,0.1}]}}]

The left handside is the model of the right handside that is easier for counting (lest the right hand side swallow lemon/gumdrops before we finish counting).

Next, let’s simulate lemongumdrops:

Exercise 7.4

Calculate the expected number of candies falling in a square of 30 x 30 (inch^2) in 15 minutes using the density given below. Denote that as ndrop, then generate ndrop number of points (each point is a candy) with {x, y} coordinates in that 30x30 square, using RandomReal[].

density=((1 lemongumdrop)/((inch^2) * 10 minutes)) ; time=15 minutes;

Answer

(* ndrop=RandomVariate[PoissonDistribution[30*30*1.5]]; *)
density=(1/((inch^2) * 10 minutes)) ; time=15 minutes;
ndrop=Floor[density*(((30 inch))^2)*time+0.5];
lgpt=RandomReal[{0,30.},{ndrop,2}];
lemongumdrop=Graphics[{Hue[0.9,1,1],PointSize[0.01],Point /@ lgpt }]

Exercise 7.5

Now, let’s see who catch what by putting mouths and lemongum raindrops together:

Show[mouth, lemongumdrop]

Count the number of candies falling in each mouth for all mouths.

Answer

We will count for each mouth by using this:

rm=1.5; rsquare=rm*rm;
catch=Reap[Do[
v=Reap[Do[c=3 {m,n}+{rm,rm};
dist=Table[(x-c) . (x-c),{x,lgpt}] ;
u=Select[dist,#≤ rsquare &];
Sow[Length[u]]
,{m,0,9}]][[2,1]];
Sow[v]
,{n,0,9}]][[2,1]] ;
catch1=Flatten @ catch;
Grid[{{Show[mouth, lemongumdrop,ImageSize-> 400]
,Show[mouth,Graphics[Table[Text[Style[catch[[m+1,n+1]],18
,Hue[((catch[[m+1,n+1]]-Min[catch1])/(Max[catch1]-Min[catch1]+1)),1,0.6]]
,3*{n,m}+{1.5,1.5}],{m,0,9},{n,0,9}]],ImageSize-> 400]}}]

There we have it. Some are very lucky with many, some are the opposite.

7.3 Histogram of candies - demo only

Grid[{{Histogram[catch1,{1},ImageSize-> 350 ]
,Histogram[catch1,{1},ChartStyle->{Hue[0.16,1,1.,0.8],Hue[0.8,0.7,1,0.8]}, Frame-> True, FrameStyle-> Black, GridLines-> Automatic
,Prolog->Inset[Show[,ImageSize-> 370]],ImageSize-> 350]
}}]

We see that the lucky one could catch 6 times more than the unlucky one. The mean is:

Mean @ catch1*1.

OK, this is what you should do. Use the code below (you don’t have to understand it at this point - later in the course, you will - just use it for now) be simulate and obtain histograms for 400 kids each time (improve our statistics with larger sampling population). Do it several times (your choice) and add themt to get more statistics until you feel confident in your answers:
- What is the chance for a kid to get only 4 lemon/gumdrops? (of course, under the same condition: 1 (lemon or gumdrop)/(inch^2) per 10 minutes and the kid stands for 15 minutes.
- what is the chance to get exactly 10? (many think it is about 50%-50% and that is very wrong).
- what is the chance to get 15 and 20, respectively 
- show your histograms.

It’s much faster if we use square mouth instead of round mouth. Here is the code for 2500 kids (50 by 50)

density=(1/( 10.)) ; time=15.; ns=50;rm=1.5;  side=rm(Sqrt[π ]);
ndrop0=density*(((ns*side))^2)*time;
ndrop=RandomVariate[PoissonDistribution[ndrop0]];
lgpt=RandomReal[{0,ns*side},{ndrop,2}];
lgpt0=Sort @ lgpt ; 
lgpt0X=lgpt0;
catch=Reap[Do[
q=Select[lgpt0X,m*side≤ #[[1]]<(m+1)*side & ];
lgpt0X=Complement[lgpt0X,q];
q0=Sort[q];
Sow[Table[Length[Select[q0,n*side≤ #[[2]]<(n+1)*side &]],{n,0,ns-1}]]
,{m,0,ns-1}]][[2,1]];
catch1=Flatten @ catch ;  total=Total[catch1];

your answer is in array catch1. The total is in total. It is up to you to plot. You can copy and paste the code above to run in your file, but you cannot copy and paste the code to plot the histogram below, because the purpose of this exercise is for you to remember the syntax of Histogram function by typing it yourself even if you have to look at the example character by character. Of course, you should always use the Help part of Mathematica.

Histogram[catch1,{1},ImageSize-> 350, Frame-> True, GridLines->Automatic, Epilog-> Inset[total,ImageScaled[{0.8,0.8}], BaseStyle-> 20] ]

This distribution is called Poisson distribution. You can read up an interesting application during WW2 when the British tried to determine if German V-1 and V-2 bombers were sufficiently accurate navigationally to target high-value facilities: https://www.britannica.com/topic/Poisson-distribution

This is another demo: you can see the distribution reaches certain shape as n-> 10,000. That shape is P[n]=(((Subscript[n, μ])^n)/(n!))(e^(-(Subscript[n, μ])))

Manipulate[
xpoisson=RandomVariate[PoissonDistribution[mean],nkids];
pmax=1.5*((mean^mean) (E^(-mean)))/mean!;
hp=Show[Histogram[xpoisson,{1},htype
,PlotRange-> {{0.,35.},{0.,pmax}}
,PlotLabel-> Style["number of lemondrops and\ngumdrops per kid",20]
,Frame-> True, FrameStyle-> Black, GridLines-> Automatic
,Epilog->Inset["number of kids "<>ToString[nkids],ImageScaled[{0.75,0.65}]
,BaseStyle->{18,FontFamily-> "Calibri"},Background->Hue[0.32,0.5,1]]]
,If[htype=="Probability"
,Graphics[{Red,PointSize[0.02],Point /@ Table[{m,((mean^m)/(m!))(E^(-mean))},{m,Ceiling[3. mean]}]}]
,Graphics[{Blue,PointSize[0.02],Point /@ Table[{m,Log[((mean^m)/(m!))]-mean},{m,Ceiling[3. mean]}]}]]]
,{{mean,10.5},3.,50.},{htype,{"Probability","LogProbability"}}
,{{nkids,1000},{100,500,1000,2500,5000,10000},ControlType->Animator ,AnimationRunning-> False(*,AnimationRunning-> True *)
,AnimationDirection-> ForwardBackward}]

8. Exercise with list, array: strings

anagramsearch[word_] := Block[{letters, vowel, set1
,setbig,wout}
,
If[StringQ[word]
,letters= DeleteCases[ StringSplit[word,""]," "];
vowel=Intersection[letters,{"a","e","i","o","u","y"}];
set1=Select[Union[Subsets[letters]]
, Length[#]≥ 2  (* 2 letters or more *)
&&  (* and  *)
IntersectingQ[#,vowel]  & 
];
setbig=Union@ Flatten[Table[   Permutations[s]   ,{s,set1}],1] ;
wout=StringJoin /@    setbig;
Select[wout, DictionaryWordQ[#,IgnoreCase->True]  & ]
,]
]

anagramsearch["scrabble"]

anagramsearch["houston"]

anagramsearch["winter"]

anagramsearch["classwork"]

anagramsearch["numerical"]

sonnet="Full many a glorious morning have I seen";
sonnS=Select[StringSplit[sonnet," "],StringLength[#]>1 &];
Grid[Transpose[{sonnS,Grid[Partition[#,8,8,1,""]] & /@ Map[anagramsearch[#] &,sonnS]}]
,BaseStyle->{24, FontFamily->"Script MT Bold"}
,Frame-> All, Alignment-> Top, Background->{{Hue[0.13,0.3,1]},}]