# Khan/khan-exercises

Older
100644 137 lines (129 sloc) 5.11 KB
 c2abb10 Add exercise: Exploring mean and median beneater authored Nov 7, 2011 1 2 3 4 5 Exploring Mean and Median 6 7 8 9
10
11 -7 12 -1 * LOWER_BOUND 13 20 random() < 0.8 ? 10 : 5 21 22 roundTo( 1, randRangeNonZero( (LOWER_BOUND + 1) * 2, (UPPER_BOUND - 1) * 2 ) / 2 ) 23 24 25 ((POINTS / 2) * (MEDIAN + 0.5) + MEDIAN - 0.5 + (POINTS / 2 - 1) * LOWER_BOUND) / POINTS 26 27 28 ((POINTS / 2) * (MEDIAN - 0.5) + MEDIAN + 0.5 + (POINTS / 2 - 1) * UPPER_BOUND) / POINTS 29 30 roundTo( 1, randRangeNonZero( MIN_MEAN * 10, MAX_MEAN * 10 ) / 10 ) 31
32
33
34
35

Arrange the POINTS orange points on the number line so the 36 arithmetic mean is MEAN 37 and the median is MEDIAN. 38 The distance between adjacent tick marks is 1.

39
40 graph.targetMedian = MEDIAN; 41 graph.targetMean = MEAN; 42 graph.numPoints = POINTS; 43 44 init({ 45 range: [ [LOWER_BOUND - 1, UPPER_BOUND + 1], [-3, 3] ] 46 }); 47 48 style({ stroke: "#bbb" }); 49 line( [ LOWER_BOUND, 0 ], [ UPPER_BOUND, 0 ] ); 50 for ( var x = LOWER_BOUND; x <= UPPER_BOUND; x++ ) { 51 line( [ x, -0.2 ], [ x, 0.2 ] ); 52 } 53 style({ strokeWidth: 3.5 }); 54 line( [ 0, -0.2 ], [ 0, 0.2 ] ); 55 label( [ 0, -0.53 ], "0", "center", {}); 56 9ffc582 Add helper marks to make mean/median easier beneater authored Nov 8, 2011 57 style({ strokeWidth: 2, stroke: BLUE, fill: BLUE, opacity: 1.0 }); 3af0746 Revert tick marks; code review fixes beneater authored Nov 8, 2011 58 graph.meanArrow = path([ c2abb10 Add exercise: Exploring mean and median beneater authored Nov 8, 2011 59 [ 0, 0.7 ], [ 0.05, 0.7 ], [ 0, 0.6 ], [ -0.05, 0.7 ], [ 0, 0.7 ], [ 0, 1.0 ] 60 ]); 3af0746 Revert tick marks; code review fixes beneater authored Nov 9, 2011 61 graph.meanLabel = label( [ 0, 1.3 ], "\\text{mean}", "above", { color: BLUE }); 62 graph.meanValueLabel = label( [ 0, 0.8 ], "0", "above", { color: BLUE }); c2abb10 Add exercise: Exploring mean and median beneater authored Nov 8, 2011 63 64 style({ strokeWidth: 2, stroke: GREEN, fill: GREEN }); 3af0746 Revert tick marks; code review fixes beneater authored Nov 9, 2011 65 graph.medianArrow = path([ c2abb10 Add exercise: Exploring mean and median beneater authored Nov 8, 2011 66 [ 0, -1.1 ], [ 0.05, -1.1 ], [ 0, -1 ], [ -0.05, -1.1 ], [ 0, -1.1 ], [ 0, -1.4 ] 67 ]); 3af0746 Revert tick marks; code review fixes beneater authored Nov 9, 2011 68 graph.medianLabel = label( [ 0, -1.7 ], "\\text{median}", "below", { color: GREEN }); 69 graph.medianValueLabel = label( [0, -1.2 ], "0", "below", { color: GREEN }); c2abb10 Add exercise: Exploring mean and median beneater authored Nov 8, 2011 70 71 addMouseLayer(); 3af0746 Revert tick marks; code review fixes beneater authored Nov 9, 2011 72 graph.points = []; c2abb10 Add exercise: Exploring mean and median beneater authored Nov 8, 2011 73 for ( var x = 0; x < POINTS; x++ ) { 3af0746 Revert tick marks; code review fixes beneater authored Nov 9, 2011 74 graph.points[x] = addMovablePoint({ c2abb10 Add exercise: Exploring mean and median beneater authored Nov 8, 2011 75 coord: [ x - POINTS / 2 + 0.5, 0 ], 76 constraints: { constrainY: true }, 77 snapX: 0.5 78 }); 79 } 80 81 graph.median = 0; 82 graph.mean = 0; 3af0746 Revert tick marks; code review fixes beneater authored Nov 9, 2011 83 jQuery.each( graph.points, function( idx, point ) { c2abb10 Add exercise: Exploring mean and median beneater authored Nov 8, 2011 84 this.onMove = function( x, y ) { 85 return onMovePoint( point, x, y ); 86 }; 87 }); 88
89
c956ce2 Change answer type name beneater authored Nov 8, 2011 90
c2abb10 Add exercise: Exploring mean and median beneater authored Nov 8, 2011 91 Move the orange dots to select your answer. 92
93 94
95

96 The median is middle number. In other words there are always as many points to the 97 right of the median as to the left. 98

99

100 Try dragging the points so that half of them are to the left of 101 MEDIAN 102 and half of them are to the right of 103 MEDIAN. 104 105 The two points in the middle should be the same distance from 106 MEDIAN. 107 108 109 The middle point should be at 110 MEDIAN. 111
112 115

116

117 As long as there are as many points to the left and to the right of the 118 median, the median will stay the same. But the arithmetic mean is calculated 119 using the value of every point. Try moving the points on either side of the 120 median closer and further from the median to see how the mean is affected. 121

122

123 There are a number of different ways to arrange the points so the mean is 124 MEAN 125 and the median is 126 MEDIAN. 127 130

131
132
133
134
135 136
Something went wrong with that request. Please try again.