SUNY Geneseo Department of Mathematics
Wednesday, February 1
Math 230 02
Spring 2017
Prof. Doug Baldwin
Geneseo programming and data science club: first meeting of the semester Thursday, Feb. 2, 6:00 - 7:00 PM, Bailey 104. With pizza!
Experimental survey for giving me anonymous questions to answer in class or feedback about this course: “Questions and Suggestions” under “Quizzes” in Canvas.
Lab: how to combine the probability of matching the powerball with the probability of matching the regular numbers?
What you need to calculate is the probability of matching the regular numbers and matching the powerball number.
Since those two events are independent (i.e., neither influences the likelihood of the other), this probability is just the product of the probabilities of the separate events: pr{regular} × pr{powerball}
Which in turn is the result calculated in step 2 times 1/p. In almost-Matlab, assuming your step 2 calculation is in a function named step2
, this might look like step2(k,n) * 1/p
Create row and column vectors of selected student’s heights (or other numbers). Find the average (with the mean
function)
Relevant reading ideas:
name( index )
>> v = [ 1, 2, 3 ]
v =
1 2 3
>> v'
ans =
1
2
3
>> [ 10; 20; 30; 40 ]'
ans =
10 20 30 40
>> v = [14,16,18,24]
v =
14 16 18 24
>> mean( v )
ans =
18
>> v2 = v'
v2 =
14
16
18
24
>> mean( v2 )
ans =
18
Example 1: Find the sum of the first n natural numbers by creating a vector of numbers 1 through n and applying the sum
function
Example 2: Find the sum of the first n odd numbers by creating a vector of n numbers evenly spaced between 1 and 2n-1 and applying the sum
function
Relevant ideas from the reading:
[ start : increment : end ]
[ 1 : n ]
to generate [ 1, 2, 3, ..., n ]linspace( start, stop, number_of_points )
or logspace( start_power, stop_power, number_of_points )
>> % Sum of first n natural numbers
>> c = [ 1 : 7 ]
c =
1 2 3 4 5 6 7
>> sum( c )
ans =
28
>> sum( [1:500] )
ans =
125250
>> % sum of first n odd numbers
>> odds = [ 1 : 2 : 113 ];
>> sum( odds )
ans =
3249
>> % nth odd number = 2n - 1
>> [ 1 : 2 : 2*100 - 1 ]
ans =
Columns 1 through 11
1 3 5 7 9 11 13 15 17 19 21
Columns 12 through 22
23 25 27 29 31 33 35 37 39 41 43
Columns 23 through 33
45 47 49 51 53 55 57 59 61 63 65
Columns 34 through 44
67 69 71 73 75 77 79 81 83 85 87
Columns 45 through 55
89 91 93 95 97 99 101 103 105 107 109
Columns 56 through 66
111 113 115 117 119 121 123 125 127 129 131
Columns 67 through 77
133 135 137 139 141 143 145 147 149 151 153
Columns 78 through 88
155 157 159 161 163 165 167 169 171 173 175
Columns 89 through 99
177 179 181 183 185 187 189 191 193 195 197
Column 100
199
>> linspace( 1, 2*100-1, 100 )
ans =
Columns 1 through 11
1 3 5 7 9 11 13 15 17 19 21
Columns 12 through 22
23 25 27 29 31 33 35 37 39 41 43
Columns 23 through 33
45 47 49 51 53 55 57 59 61 63 65
Columns 34 through 44
67 69 71 73 75 77 79 81 83 85 87
Columns 45 through 55
89 91 93 95 97 99 101 103 105 107 109
Columns 56 through 66
111 113 115 117 119 121 123 125 127 129 131
Columns 67 through 77
133 135 137 139 141 143 145 147 149 151 153
Columns 78 through 88
155 157 159 161 163 165 167 169 171 173 175
Columns 89 through 99
177 179 181 183 185 187 189 191 193 195 197
Column 100
199
>> n = 2
n =
2
>> sum( linspace( 1, 2*n-1, n ) )
ans =
4
>> n = 3
n =
3
>> sum( linspace( 1, 2*n-1, n ) )
ans =
9
>> n = 4
n =
4
>> sum( linspace( 1, 2*n-1, n ) )
ans =
16
>> n = 2
n =
2
>> sum( [1:n] )
ans =
3
>> n = 3
n =
3
>> sum( [1:n] )
ans =
6
Notice any patterns to the sums?
Calculating with vectors
Read sections 4.6 - 4.7