Day 2 # Mathematica
Resources and Exercise
How to open Mathematica Notebook
1. Click on window button 2. Search for Mathematica (Do not use Mathematica Kernel) 3. Click on the Mathematica programme 4. Click on file menu 5. Click on New menu 6. Click on Notebook(.nb) menu (a new Mathematica notebook will open)
Vocabulary: Elementary Arithmetic
2+2 addition 5-2 subtraction 2*3 multiplication (2 3 also works) 6/2 division 3^2 raising to a power (e.g. squaring)
Exercise: Elementary Arithmetic
1.1 Compute 1+2+3. Write syntax and press Shift+Enter Key 1+2+3 or Plus[1,2,3] 1.2 Add the numbers 1, 2, 3, 4, 5. Write syntax and press Shift+Enter Key 1+2+3+4+5 or Plus[1,2,3,4,5] 1.3 Multiply the numbers 1, 2, 3, 4, 5.Write syntax and press Shift+Enter Key 1 2 3 4 5 or 1*2*3*4*5 or Times[1,2,3,4,5] 1.4 Compute 5 squared .Write syntax and press Shift+Enter Key 5 5 or 5*5 or Power[5,2] 1.5 Compute 3 raised to the fourth power. 3^4 1.6 Compute 10 raised to the power 12 . 10^12 1.7 Compute 3 raised to the power 7×8. 3^(7 8) 1.8 Add parentheses to 4-2*3+4 to make 14. (4-2)*(3+4) 1.9 Compute twenty-nine thousand multiplied by seventy-three. 29000 x 73 +1.1 Add all integers from -3 to +3. Total[Range[-3,3]] +1.2 Compute 24 divided by 3. 45/2 +1.3 Compute 5 raised to the power 100. 5^(100) +1.4 Subtract 5 squared from 100. 100-5^2 +1.5 Multiply 6 by 5 squared, and add 7. 6*5^2+7 +1.6 Compute 3 squared minus 2 cubed. 3^2-2^3 +1.7 Compute 2 cubed times 3 squared. 2^3*3^2 +1.8 Compute “double the sum of eight and negative eleven”. 2*((8+(-11))
Vocabulary: Introducing Function
Plus[2,2] 2+2 addition Subtract[5,2] 5-2 subtraction Times[2,3] 2*3 multiplication (2 3 also works) Divide[6,2] 6/2 division Power[3,2] 3^2 raising to a power Max[3,4] maximum (largest) Min[3,4] minimum (smallest) RandomInteger[10] random whole number
Exercise: Introducing Function
2.1 Compute 7+6+5 using the function Plus. Plus[7,6,5] 2.2 Compute 2×(3+4) using Times and Plus. Times[ Plus[3,4],2] 2.3 Use Max to find the larger of 6×8 and 5×9. Max[Times[6,8],Times[5,9]] 2.4 Use RandomInteger to generate a random number between 0 and 1000. RandomInteger[1000] 2.5 Use Plus and RandomInteger to generate a number between 10 and 20. Plus[RandomInteger[10],10] +2.1 Compute 5×4×3×2 using Times. Times[5,4,3,2] +2.2 Compute 2−3 using Subtract. Subtract[2,3] +2.3 Compute (8+7)*(9+2) using Times and Plus. Times[Plus[8,7],Plus[9,2]] +2.4 Compute (26−89)/9 using Subtract and Divide. +2.5 Compute 100−5^2 using Subtract and Power. +2.6 Find the larger of 3^5 and 5^3. +2.7 Multiply 3 and the larger of 4^3 and 3^4. +2.8 Add two random numbers each between 0 and 1000.
Vocabulary: List Function
{1,2,3,4} list of elements ListPlot[{1,2,3,4}] plot a list of numbers Range[10] range of numbers Reverse[{1,2,3}] reverse a list Join[{4,5,6},{2,3,2}] join lists together
Exercise: List Function
3.1 Use Range to create the list {1, 2, 3, 4}. Range[4] 3.2 Make a list of numbers up to 100. Range[100] 3.3 Use Range and Reverse to create {4, 3, 2, 1}. Reverse[Range[4]] 3.4 Make a list of numbers from 1 to 50 in reverse order. Reverse[Range[50]] 3.5 Use Range, Reverse and Join to create {1, 2, 3, 4, 4, 3, 2, 1}. Join[Range[4],Reverse[Range[4]]] 3.6 Plot a list that counts up from 1 to 100, then down to 1. ListPlot[Join[Range[100],Reverse[Range[100]]]] 3.7 Use Range and RandomInteger to make a list with a random length up to 10. Range[RandomInteger[10]] 3.8 Find a simpler form for Reverse[Reverse[Range[10]]]. Range[10] 3.9 Find a simpler form for Join[{1, 2}, Join[{3, 4}, {5}]]. Join[{1,2},{3,4},{5}] 3.10 Find a simpler form for Join[Range[10], Join[Range[10], Range[5]]]. Join[Range[10],Range[10],Range[5]] 3.11 Find a simpler form for Reverse[Join[Range[20], Reverse[Range[20]]]]. Join[Range[20],Reverse[Range[20]]] +3.1 Compute the reverse of the reverse of {1, 2, 3, 4}. +3.2 Use Range, Reverse and Join to create the list {1, 2, 3, 4, 5, 4, 3, 2, 1}. +3.3 Use Range, Reverse and Join to create {3, 2, 1, 4, 3, 2, 1, 5, 4, 3, 2, 1}. +3.4 Plot the list of numbers {10, 11, 12, 13, 14}. +3.5 Find a simpler form for Join[Join[Range[10], Reverse[Range[10]]], Range[10]].
Vocabulary: Disply using List
ListLinePlot[{1,2,5}] values joined by a line BarChart[{1,2,5}] bar chart (values give bar heights) PieChart[{1,2,5}] pie chart (values give wedge sizes) NumberLinePlot[{1,2,5}] numbers arranged on a line Column[{1,2,5}] elements displayed in a column
Vocabulary: Display using List
4.1 Make a bar chart of {1, 1, 2, 3, 5}. BarChart[{1,1,2,3,5}] 4.2 Make a pie chart of numbers from 1 to 10. PieChart[Range[10]] 4.3 Make a bar chart of numbers counting down from 20 to 1. BarChart[Reverse[Range[20]]] 4.4 Display numbers from 1 to 5 in a column. Display numbers from 1 to 5 in a column. 4.5 Make a number line plot of the squares {1, 4, 9, 16, 25}. NumberLinePlot[Range[5]^2] 4.6 Make a pie chart with 10 identical segments, each of size 1. PieChart[Table[1,10]] 4.7 Make a column of pie charts with 1, 2 and 3 identical segments. Column[{PieChart[{1}],PieChart[{1,1}],PieChart[{1,1,1}]}] +4.1 Make a list of pie charts with 1, 2 and 3 identical segments. +4.2 Make a bar chart of the sequence 1, 2, 3, ..., 9, 10, 9, 8, 7, ..., 1. +4.3 Make a list of a pie chart, bar chart and line plot of the numbers from 1 to 10. +4.4 Make a list of a pie chart and a bar chart of {1, 1, 2, 3, 5, 8, 13, 21, 34, 55}. +4.5 Make a column of two number line plots of {1, 2, 3, 4, 5}. +4.6 Make a number line of fractions 1/2, 1/3, ... through 1/9.
Vocabulary: Operation on List
{2,3,4}+{5,6,2} arithmetic on lists Sort[{5,7,1}] sort a list into order Length[{3,3}] length of a list (number of elements) Total[{1,1,2}] total of all elements in a list Count[{3,2,3},3] count occurrences of an element First[{2,3}] first element in a list Last[{6,7,8}] last element in a list Part[{3,1,4},2] particular part of a list, also written as {3, 1, 4}[[2]] Take[{6,4,3,1},2] take elements from the beginning of a list Drop[{6,4,3,1},2] drop elements from the beginning of a list IntegerDigits[1234] list of digits in a number
Exercise: Operation on List
5.1 Make a list of the first 10 squares, in reverse order. Reverse[Range[10]^2] 5.2 Find the total of the first 10 squares. Total[Range[10]^2] 5.3 Make a plot of the first 10 squares, starting at 1. ListPlot[Range[10]^2] 5.4 Use Sort, Join and Range to create {1, 1, 2, 2, 3, 3, 4, 4}. Sort[Join[Range[4],Range[4]]] 5.5 Use Range and + to make a list of numbers from 10 to 20, inclusive. Range[11]+9 5.6 Make a combined list of the first 5 squares and cubes, sorted into order. Sort[Join[Range[5]^2,Range[5]^3]] 5.7 Find the number of digits in 2^128. Length[IntegerDigits[2^128]] 5.8 Find the first digit of 2^32. IntegerDigits[2^32][[1]] 5.9 Find the first 10 digits in 2^100. Take[IntegerDigits[2^100],10] 5.10 Find the largest digit that appears in 2^20. Max[IntegerDigits[2^20]] 5.11 Find how many zeros appear in the digits of 2^1000. Count[IntegerDigits[2^1000],0] 5.12 Use Part, Sort and IntegerDigits to find the second-smallest digit in 2^20. Sort[IntegerDigits[2^20]] 5.13 Make a line plot of the sequence of digits that appear in 2^128. ListLinePlot[IntegerDigits[2^128]] 5.14 Use Take and Drop to get the sequence 11 through 20 from Range[100]. Drop[Take[Range[100],20],10] +5.1 Make a list of the first 10 multiples of 3. Range[10]*3 +5.2 Make a list of the first 10 squares using only Range and Times. Times[Range[10],Range[10]] +5.3 Find the last digit of 2^37. Last[IntegerDigits[2^37]] +5.4 Find the second-to-last digit of 2^32. IntegerDigits[2^32][[-2]] +5.5 Find the sum of all the digits of 3^126. Total[IntegerDigits[3^126]] +5.6 Make a pie chart of the sequence of digits that appear in 2^32. PieChart[IntegerDigits[2^32]] +5.7 Make a list of pie charts for the sequence of digits in 2^20, 2^40, 2^60. List[PieChart[IntegerDigits[2^20]],PieChart[IntegerDigits[2^40]],PieChart[IntegerDigits[2^60]]]
Vocabulary: Tables
Table[x,5] list of 5 copies of x Table[f[n],{n,10}] list of values of f[n] with n going up to 10 Table[f[n],{n,2,10}] list of values with n going from 2 to 10 Table[f[n],{n,2,10,4}] list of values with n going from 2 to 10 in steps of 4 Range[5,10] list of numbers from 5 to 10 Range[10,20,2] list of numbers from 10 to 20 in steps of 2 RandomInteger[10,20] list of 20 random integers up to 10
Exercise: Tables
6.1 Make a list in which the number 1000 is repeated 5 times. Table[1000,5] 6.2 Make a table of the values of n^3 for n from 10 to 20. Table[n^3,{n,10,20}] 6.3 Make a number line plot of the first 20 squares. NumberLinePlot[Table[n^2,{n,20}]] 6.4 Make a list of the even numbers (2, 4, 6, ...) up to 20. Table[2 n,{n,1,10}] 6.5 Use Table to get the same result as Range[10]. Table[n,{n,1,10}] 6.6 Make a bar chart of the first 10 squares. BarChart[Table[n^2,{n,1,10}]] 6.7 Make a table of lists of digits for the first 10 squares. Table[IntegerDigits[n^2],{n,1,10}] 6.8 Make a list line plot of the length of the sequence of digits for each of the first 100 squares. ListLinePlot[Table[Length[IntegerDigits[n^2]],{n,1,100}]] 6.9 Make a table of the first digit of the first 20 squares. Table[First[IntegerDigits[n^2]],{n,1,20}] 6.10 Make a list line plot of the first digits of the first 100 squares. ListLinePlot[Table[First[IntegerDigits[n^2]],{n,1,100}]] +6.1 Make a list of the differences between n^3 and n^2 with n up to 10. Table[n^3-n^2,{n,1,10}] +6.2 Make a list of the odd numbers (1, 3, 5, ...) up to 100. Table[2 n-1,{n,1,50}] +6.3 Make a list of the squares of even numbers up to 100. Table[(2 n)^2,{n,1,50}] +6.4 Create the list {-3, -2, -1, 0, 1, 2} using Range. Range[-3,2] +6.5 Make a list for numbers n up to 20 in which each element is a column of the values of n, n^2 and n^3. Table[Column[{n,n^2,n^3}],{n,1,20}] +6.6 Make a list line plot of the last digits of the first 100 squares. ListLinePlot[Table[Last[IntegerDigits[n^2]],{n,1,100}]] +6.7 Make a list line plot of the first digit of the first 100 multiples of 3. ListLinePlot[Table[First[IntegerDigits[3 n]],{n,1,100}]] +6.8 Make a list line plot of the total of the digits for each number up to 200. ListLinePlot[Table[Total[IntegerDigits[n]],{n,1,200}]] +6.9 Make a list line plot of the total of the digits for each of the first 100 squares. ListLinePlot[Table[Total[IntegerDigits[n^2]],{n,1,100}]] +6.10 Make a number line plot of the numbers 1/n with n from 1 to 20. NumberLinePlot[Table[1/n,{n,1,20}]] +6.11 Make a line plot of a list of 100 random integers where the nth integer is between 0 and n. ListLinePlot[Table[RandomInteger[n],{n,1,100}]]
No comments:
Post a Comment