Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 196 lines (188 sloc) 9.148 kb
c2abb10 @beneater Add exercise: Exploring mean and median
beneater authored
1 <!DOCTYPE html>
2 <html data-require="math graphie interactive mean-and-median">
3 <head>
4e4cb9b @beneater lint: tabs->spaces and jQuery->$ for exercises
beneater authored
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <title>Exploring mean and median</title>
6 <script src="../khan-exercise.js"></script>
c2abb10 @beneater Add exercise: Exploring mean and median
beneater authored
7 </head>
8 <body>
4e4cb9b @beneater lint: tabs->spaces and jQuery->$ for exercises
beneater authored
9 <div class="exercise">
10 <div class="vars">
11 <var id="LOWER_BOUND">-7</var>
12 <var id="UPPER_BOUND">-1 * LOWER_BOUND</var>
13 <!--
3530641 @beneater Add a <br /> to exploring_mean_and_median question #FIXIT
beneater authored
14 80% chance of getting 10 points to work with; otherwise 5. Any
15 other reasonable quantity leads to really messy means. This at
16 least covers both cases: where the median is a point, and
17 where the median is between two points. Weighted towards more
18 problems with 10 points to make it easier to get the intuition
19 how/why the mean and median can vary.
4e4cb9b @beneater lint: tabs->spaces and jQuery->$ for exercises
beneater authored
20 -->
21 <var id="POINTS">random() &lt; 0.8 ? 10 : 5</var>
22 <var id="MEDIAN">
3530641 @beneater Add a <br /> to exploring_mean_and_median question #FIXIT
beneater authored
23 roundTo(1, randRangeNonZero((LOWER_BOUND + 1) * 2,
24 (UPPER_BOUND - 1) * 2) / 2)
4e4cb9b @beneater lint: tabs->spaces and jQuery->$ for exercises
beneater authored
25 </var>
26 <var id="MIN_MEAN">
3530641 @beneater Add a <br /> to exploring_mean_and_median question #FIXIT
beneater authored
27 ((POINTS / 2) * (MEDIAN + 0.5) + MEDIAN - 0.5 +
28 (POINTS / 2 - 1) * LOWER_BOUND) / POINTS
4e4cb9b @beneater lint: tabs->spaces and jQuery->$ for exercises
beneater authored
29 </var>
30 <var id="MAX_MEAN">
3530641 @beneater Add a <br /> to exploring_mean_and_median question #FIXIT
beneater authored
31 ((POINTS / 2) * (MEDIAN - 0.5) + MEDIAN + 0.5 +
32 (POINTS / 2 - 1) * UPPER_BOUND) / POINTS
33 </var>
34 <var id="MEAN">
35 roundTo(1, randRangeNonZero(MIN_MEAN * 10, MAX_MEAN * 10) / 10)
4e4cb9b @beneater lint: tabs->spaces and jQuery->$ for exercises
beneater authored
36 </var>
37 </div>
38 <div class="problems">
39 <div>
40 <div class="question">
3530641 @beneater Add a <br /> to exploring_mean_and_median question #FIXIT
beneater authored
41 <p>Arrange the <var>POINTS</var> orange points on the
42 number line so the <span class="hint_blue">arithmetic mean
43 is <code><var>MEAN</var></code></span><br /> and the
44 <span class="hint_green">median is
45 <code><var>MEDIAN</var></code></span>.
4e4cb9b @beneater lint: tabs->spaces and jQuery->$ for exercises
beneater authored
46 The distance between adjacent tick marks is 1.</p>
47 <div class="graphie" id="number-line">
48 graph.targetMedian = MEDIAN;
49 graph.targetMean = MEAN;
50 graph.numPoints = POINTS;
c2abb10 @beneater Add exercise: Exploring mean and median
beneater authored
51
4e4cb9b @beneater lint: tabs->spaces and jQuery->$ for exercises
beneater authored
52 init({
3530641 @beneater Add a <br /> to exploring_mean_and_median question #FIXIT
beneater authored
53 range: [
064281e @beneater Fix up exercises that are too wide for tutorials
beneater authored
54 [LOWER_BOUND - 0.3, UPPER_BOUND + 0.2],
3530641 @beneater Add a <br /> to exploring_mean_and_median question #FIXIT
beneater authored
55 [-3, 3]],
56 scale: 35
4e4cb9b @beneater lint: tabs->spaces and jQuery->$ for exercises
beneater authored
57 });
c2abb10 @beneater Add exercise: Exploring mean and median
beneater authored
58
4e4cb9b @beneater lint: tabs->spaces and jQuery->$ for exercises
beneater authored
59 style({ stroke: "#bbb" });
3530641 @beneater Add a <br /> to exploring_mean_and_median question #FIXIT
beneater authored
60 line([LOWER_BOUND, 0], [UPPER_BOUND, 0]);
61 for (var x = LOWER_BOUND; x &lt;= UPPER_BOUND; x++) {
62 line([x, -0.2], [x, 0.2]);
4e4cb9b @beneater lint: tabs->spaces and jQuery->$ for exercises
beneater authored
63 }
64 style({ strokeWidth: 3.5 });
3530641 @beneater Add a <br /> to exploring_mean_and_median question #FIXIT
beneater authored
65 line([0, -0.2], [0, 0.2]);
66 label([0, -0.53], "0", "center", {});
c2abb10 @beneater Add exercise: Exploring mean and median
beneater authored
67
3530641 @beneater Add a <br /> to exploring_mean_and_median question #FIXIT
beneater authored
68 style({
69 strokeWidth: 2,
70 stroke: BLUE,
71 fill: BLUE,
72 opacity: 1.0
73 });
4e4cb9b @beneater lint: tabs->spaces and jQuery->$ for exercises
beneater authored
74 graph.meanArrow = path([
3530641 @beneater Add a <br /> to exploring_mean_and_median question #FIXIT
beneater authored
75 [0, 0.7], [0.05, 0.7], [0, 0.6],
76 [-0.05, 0.7], [0, 0.7], [0, 1.0]
4e4cb9b @beneater lint: tabs->spaces and jQuery->$ for exercises
beneater authored
77 ]);
3530641 @beneater Add a <br /> to exploring_mean_and_median question #FIXIT
beneater authored
78 graph.meanLabel = label([0, 1.3], "\\text{mean}",
79 "above", { color: BLUE });
80 graph.meanValueLabel = label([0, 0.8], "0",
81 "above", { color: BLUE });
c2abb10 @beneater Add exercise: Exploring mean and median
beneater authored
82
4e4cb9b @beneater lint: tabs->spaces and jQuery->$ for exercises
beneater authored
83 style({ strokeWidth: 2, stroke: GREEN, fill: GREEN });
84 graph.medianArrow = path([
3530641 @beneater Add a <br /> to exploring_mean_and_median question #FIXIT
beneater authored
85 [0, -1.1], [0.05, -1.1], [0, -1],
86 [-0.05, -1.1], [0, -1.1], [0, -1.4]
4e4cb9b @beneater lint: tabs->spaces and jQuery->$ for exercises
beneater authored
87 ]);
3530641 @beneater Add a <br /> to exploring_mean_and_median question #FIXIT
beneater authored
88 graph.medianLabel = label([0, -1.7], "\\text{median}",
89 "below", { color: GREEN });
90 graph.medianValueLabel = label([0, -1.2], "0",
91 "below", { color: GREEN });
c2abb10 @beneater Add exercise: Exploring mean and median
beneater authored
92
4e4cb9b @beneater lint: tabs->spaces and jQuery->$ for exercises
beneater authored
93 addMouseLayer();
94 graph.points = [];
3530641 @beneater Add a <br /> to exploring_mean_and_median question #FIXIT
beneater authored
95 for (var x = 0; x &lt; POINTS; x++) {
4e4cb9b @beneater lint: tabs->spaces and jQuery->$ for exercises
beneater authored
96 graph.points[x] = addMovablePoint({
3530641 @beneater Add a <br /> to exploring_mean_and_median question #FIXIT
beneater authored
97 coord: [x - POINTS / 2 + 0.5, 0],
4e4cb9b @beneater lint: tabs->spaces and jQuery->$ for exercises
beneater authored
98 constraints: { constrainY: true },
99 snapX: 0.5
100 });
101 }
c2abb10 @beneater Add exercise: Exploring mean and median
beneater authored
102
4e4cb9b @beneater lint: tabs->spaces and jQuery->$ for exercises
beneater authored
103 graph.median = 0;
104 graph.mean = 0;
105 graph.moved = false;
3530641 @beneater Add a <br /> to exploring_mean_and_median question #FIXIT
beneater authored
106 $.each(graph.points, function(idx, point) {
107 this.onMove = function(x, y) {
4e4cb9b @beneater lint: tabs->spaces and jQuery->$ for exercises
beneater authored
108 graph.moved = true;
3530641 @beneater Add a <br /> to exploring_mean_and_median question #FIXIT
beneater authored
109 return onMovePoint(point, x, y,
110 updateMeanAndMedian);
4e4cb9b @beneater lint: tabs->spaces and jQuery->$ for exercises
beneater authored
111 };
112 });
113 </div>
114 </div>
115 <div class="solution" data-type="custom">
116 <div class="instruction">
117 Move the orange dots to select your answer.
118 </div>
3530641 @beneater Add a <br /> to exploring_mean_and_median question #FIXIT
beneater authored
119 <div class="guess">$.map(graph.points, function(el) {
120 return el.coord[0];
121 })</div>
4e4cb9b @beneater lint: tabs->spaces and jQuery->$ for exercises
beneater authored
122 <div class="validator-function">
3530641 @beneater Add a <br /> to exploring_mean_and_median question #FIXIT
beneater authored
123 if (roundTo(1, mean(guess)) === MEAN &amp;&amp;
124 roundTo(1, median(guess)) === MEDIAN) {
4e4cb9b @beneater lint: tabs->spaces and jQuery->$ for exercises
beneater authored
125 return true;
3530641 @beneater Add a <br /> to exploring_mean_and_median question #FIXIT
beneater authored
126 } else if (graph.moved) {
4e4cb9b @beneater lint: tabs->spaces and jQuery->$ for exercises
beneater authored
127 return false;
128 } else {
129 return "";
130 }
131 </div>
132 <div class="show-guess">
3530641 @beneater Add a <br /> to exploring_mean_and_median question #FIXIT
beneater authored
133 $.each(guess, function(i, x) {
134 onMovePoint(graph.points[i], x, 0);
4e4cb9b @beneater lint: tabs->spaces and jQuery->$ for exercises
beneater authored
135 });
136 updateMeanAndMedian();
137 </div>
3530641 @beneater Add a <br /> to exploring_mean_and_median question #FIXIT
beneater authored
138 <div class="example">
139 any arrangement of the orange dots so that the mean
140 and median are correct
141 </div>
4e4cb9b @beneater lint: tabs->spaces and jQuery->$ for exercises
beneater authored
142 </div>
c2abb10 @beneater Add exercise: Exploring mean and median
beneater authored
143
4e4cb9b @beneater lint: tabs->spaces and jQuery->$ for exercises
beneater authored
144 <div class="hints">
145 <p>
3530641 @beneater Add a <br /> to exploring_mean_and_median question #FIXIT
beneater authored
146 The median is the middle number. In other words there
147 are always as many points to the right of the median
148 as to the left.
4e4cb9b @beneater lint: tabs->spaces and jQuery->$ for exercises
beneater authored
149 </p>
150 <p>
3530641 @beneater Add a <br /> to exploring_mean_and_median question #FIXIT
beneater authored
151 Try dragging the points so that half of them are to
152 the left of <span class="hint_green">
153 <code><var>MEDIAN</var></code></span> and half of them
154 are to the right of <span class="hint_green">
155 <code><var>MEDIAN</var></code></span>.
4e4cb9b @beneater lint: tabs->spaces and jQuery->$ for exercises
beneater authored
156 <span data-if="POINTS % 2 === 0">
3530641 @beneater Add a <br /> to exploring_mean_and_median question #FIXIT
beneater authored
157 The two points in the middle should be the same
158 distance from <span class="hint_green">
159 <code><var>MEDIAN</var></code></span>.
4e4cb9b @beneater lint: tabs->spaces and jQuery->$ for exercises
beneater authored
160 </span>
161 <span data-else>
162 The middle point should be at
3530641 @beneater Add a <br /> to exploring_mean_and_median question #FIXIT
beneater authored
163 <span class="hint_green">
164 <code><var>MEDIAN</var></code></span>.
4e4cb9b @beneater lint: tabs->spaces and jQuery->$ for exercises
beneater authored
165 </span><br />
3530641 @beneater Add a <br /> to exploring_mean_and_median question #FIXIT
beneater authored
166 <input type="button" value="Show me an example"
167 onClick="javascript:
168 KhanUtil.showMedianExample();
169 ">
4e4cb9b @beneater lint: tabs->spaces and jQuery->$ for exercises
beneater authored
170 </p>
171 <p>
3530641 @beneater Add a <br /> to exploring_mean_and_median question #FIXIT
beneater authored
172 As long as there are as many points to the left and to
173 the right of the median, the median will stay the same.
174 But the arithmetic mean is calculated using the value
175 of every point. Try moving the points on either side
176 of the median closer and further from the median to
177 see how the mean is affected.
4e4cb9b @beneater lint: tabs->spaces and jQuery->$ for exercises
beneater authored
178 </p>
179 <p>
3530641 @beneater Add a <br /> to exploring_mean_and_median question #FIXIT
beneater authored
180 There are a number of different ways to arrange the
181 points so the mean is <span class="hint_blue">
182 <code><var>MEAN</var></code></span> and the median is
183 <span class="hint_green">
184 <code><var>MEDIAN</var></code></span>.
185 <input type="button" value="Show me an example"
186 onClick="javascript:
187 KhanUtil.showMeanExample();
188 ">
4e4cb9b @beneater lint: tabs->spaces and jQuery->$ for exercises
beneater authored
189 </p>
190 </div>
191 </div>
192 </div>
193 </div>
c2abb10 @beneater Add exercise: Exploring mean and median
beneater authored
194 </body>
195 </html>
Something went wrong with that request. Please try again.