## Day 3 # Mathematica

Resources and Exercise

#### Vocabulary: Basic Graphics Objects

Circle[ ] specify a circle Disk[ ] specify a filled‐in disk RegularPolygon[n] specify a regular polygon with n sides Graphics[object] display an object as graphics Sphere[ ], Cylinder[ ], Cone[ ], ... specify 3D geometric shapes Graphics3D[object] display an object as 3D graphics

#### Exercise: Basic Graphics Objects

8.1 Use RegularPolygon to draw a triangle. Graphics[RegularPolygon[3]] 8.2 Make graphics of a red circle. Graphics[{Red,Circle[]}] 8.3 Make a red octagon. Graphics[{Red,RegularPolygon[8]}] 8.4 Make a list whose elements are disks with hues varying from 0 to 1 in steps of 0.1. Table[Graphics[{Hue[i],Disk[]}],{i,0,1,0.1}] 8.5 Make a column of a red and a green triangle. Column[Table[Graphics[{i,RegularPolygon[3]}],{i,{Red,Green}}]] 8.6 Make a list giving the regular polygons with 5 through 10 sides, with each polygon being colored pink. Table[Graphics[{Pink,RegularPolygon[n]}],{n,5,10}] 8.7 Make a graphic of a purple cylinder. Graphics3D[{Purple,Cylinder[]}] 8.8 Make a list of polygons with 8, 7, 6, ... , 3 sides, and colored with RandomColor, then show them all overlaid with the triangle on top (hint: apply Graphics to the list). Graphics[Table[{RandomColor[],RegularPolygon[n]},{n,8,3,-1}]] +8.1 Make a list of 10 regular pentagons with random colors. Table[Graphics[{RandomColor[],RegularPolygon[5]}],10] +8.2 Make a list of a 20-sided regular polygon and a disk. List[Graphics[RegularPolygon[20]],Graphics[Disk[]]] +8.3 Make a list of polygons with 10, 9, ... , 3 sides. Table[Graphics[RegularPolygon[n]],{n,10,3,-1}]

#### Vocabulary: Interactive Manipulation

Manipulate[anything,{n,0,10,1}] manipulate anything with n varying in steps of 1 Manipulate[anything,{x,0,10}] manipulate anything with x varying continuously

#### Exercise: Interactive Manipulation

9.1 Make a Manipulate to show Range[n] with n varying from 0 to 100. Manipulate[Range[n],{n,0,100}] 9.2 Make a Manipulate to plot the whole numbers up to n, where n can range from 5 to 50. Manipulate[ListPlot[Range[n]],{n,5,50,1}] 9.3 Make a Manipulate to show a column of between 1 and 10 copies of x. Manipulate[Column[Table[x,n]],{n,1,10}] 9.4 Make a Manipulate to show a disk with a hue varying from 0 to 1. Manipulate[Graphics[Style[Disk[],Hue[h]]],{h,0,1}] 9.5 Make a Manipulate to show a disk with red, green and blue color components varying from 0 to 1. Manipulate[Graphics[Style[Disk[],RGBcolor[red,green,blue]]],{red,0,1},{green,0,1},{blue,0,1}] 9.6 Make a Manipulate to show digit sequences of 4-digit integers (between 1000 and 9999). Manipulate[IntegerDigits[n],{n,1000,9999,1}] 9.7 Make a Manipulate to create a list of between 5 and 50 equally spaced hues. Manipulate[ Table[Hue[i/n], {i, 0, n - 1}], {n, 5, 50, 1}] 9.8 Make a Manipulate that shows a list of a variable number of hexagons (between 1 and 10), and with variable hues. Manipulate[Table[Graphics[Style[RegularPolygon[6],Hue[h]]],n],{n,1,10},{h,0,1,1/n}] 9.9 Make a Manipulate that lets you show a regular polygon with between 5 and 20 sides, in red, yellow or blue. Manipulate[Graphics[{c,RegularPolygon[n]}],{n,5,20,1},{c,{Red, Yellow,Blue}}] 9.10 Make a Manipulate that shows a pie chart with a number of equal segments varying from 1 to 10. Manipulate[Graphics[PieChart[Table[1,n]]],{n,1,10}] 9.11 Make a Manipulate that gives a bar chart of the 3 digits in integers from 100 to 999. Manipulate[BarChart[IntegerDigits[n]],{n,100,999,1}] 9.12 Make a Manipulate that shows n random colors, where n can range from 1 to 50. Manipulate[RandomColor[n],{n,1,50,1}] 9.13 Make a Manipulate to display a column of integer powers with bases from 1 to 25 and exponents from 1 to 10. Manipulate[Column[Table[a^k,{k,1,n,1}]],{n,1,10,1},{a,1,25,1}] 9.14 Make a Manipulate of a number line of values of x^n for integer x from 1 to 10, with n varying from 0 to 5. Manipulate[NumberLinePlot[Range[10]^n],{n,0,5,1}] 9.15 Make a Manipulate to show a sphere that can vary in color from green to red. Manipulate[Graphics3D[{Hue[n],Sphere[]}],{n,0.33,1}] +9.1 Make a Manipulate to plot numbers from 1 to 100 raised to powers that can vary between −1 and +1. Manipulate[ListPlot[Range[100]^n],{n,-1,1,1}] +9.2 Make a Manipulate to display 1000 at sizes between 5 and 100. Manipulate[Style["1000",n],{n,5,100,1}] +9.3 Make a Manipulate to show a bar chart with 4 bars, each with a height that can be between 0 and 10.

#### Vocabulary: Coordinates and Graphics

Point[{x,y}] a point at coordinates {x, y} Line[{{1,1},{2,4},{1,2}}] a line connecting specified coordinates Circle[{x,y}] a circle with center at {x, y} Circle[{x,y},r] a circle with center at {x, y} and radius r RegularPolygon[{x,y},s,n] a regular polygon with center {x, y} and n sides each s long Polygon[{{1,1},{2,4},{1,2}}] a polygon with the specified corners Sphere[{x,y,z}] a sphere with center at {x, y, z} Sphere[{x,y,z},r] a sphere with center at {x, y, z} and radius r Opacity[level] specify an opacity level (0: transparent; 1: solid)

#### Exercise: Coordinates and Graphics

14.1 Make graphics of 5 concentric circles centered at {0, 0} with radii 1, 2, ... , 5. Graphics[Table[Circle[{0,0},r],{r,5}]] 14.2 Make 10 concentric circles with random colors. Graphics[Table[{RandomColor[],Circle[{0,0},r]},{r,10}]] 14.3 Make graphics of a 10×10 grid of circles with radius 1 centered at integer points {x, y}. Graphics[Table[Circle[{x,y}],{x,1,10},{y,1,10}]] 14.4 Make a 10×10 grid of points with coordinates at integer positions up to 10. Graphics[Table[Point[{x,y}],{x,1,10},{y,1,10}]] 14.5 Make a Manipulate with between 1 and 20 concentric circles. Manipulate[Graphics[Table[Circle[{0,0},r],{r,1,n}]],{n,1,20}] 14.6 Place 50 spheres with random colors at random integer coordinates up to 10. Graphics3D[Table[{RandomColor[],Sphere[RandomInteger[10,3]]},50]] 14.7 Make a 10×10×10 array of spheres with RGB components ranging from 0 to 1. The spheres should be centered at integer coordinates, and should just touch each other. The RGB components of each sphere should be in direct proportion to the x,y,z components of that sphere's center. Graphics3D[ Table[Style[Sphere[{x, y, z}, 0.5], RGBColor[x/10, y/10, z/10]], {x,10}, {y,10}, {z, 10}]] 14.8 Make a Manipulate with t varying between −2 and +2 that contains circles of radius x centered at {t*x, 0} with x going from 1 to 10. Manipulate[Graphics[Table[Circle[{t*x,0},x],{x,1,10,1}]],{t,-2,2}] 14.9 Make a 5×5 array of regular hexagons with size 1/2, centered at integer points. Graphics[Table[RegularPolygon[{x,y},1/2,6],{x,5},{y,5}]] 14.10 Make a line in 3D that goes through 50 random points with integer coordinates randomly chosen up to 50. Graphics3D[Line[Table[RandomInteger[50,3],50]]] +14.1 Make a Manipulate to create an n×n regular grid of points at integer positions, with n going from 5 to 20. Manipulate[Graphics[Table[Point[{x,y}],{x,1,n},{y,1,n}]],{n,5,20}] +14.2 Place 30 radius-1 circles with random colors at random integer coordinates up to 10. Graphics[Table[{RandomColor[],Circle[RandomInteger[10,2],1]},30]] +14.3 Display 100 polygons with side length 10, opacity .5, and random choices of colors, sides between 3 and 8, and integer coordinates up to 100. Graphics[Table[Style[RegularPolygon[RandomInteger[100,2],10,RandomInteger[{3,8}]],RandomColor[],Opacity[0.5]],100]] +14.4 Make a 10×10×10 array of points in 3D, with each point having a random color. Graphics3D[Table[{RandomColor[],Point[{x,y,z}]},{x,10},{y,10},{z,10}]] +14.5 Take the first two digits of numbers from 10 to 100 and draw a line that uses them as coordinates. Graphics[Line[Table[Take[IntegerDigits[x],2],{x,10,100,1}]]] +14.6 Take the first 3 digits of numbers from 100 to 1000 and draw a line in 3D that uses them as coordinates. Graphics3D[Line[Table[Take[IntegerDigits[x],3],{x,100,1000,1}]]]

## No comments:

## Post a Comment