This repository has been archived by the owner on May 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 863
/
derivative_intuition.html
185 lines (171 loc) · 8.93 KB
/
derivative_intuition.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<!DOCTYPE html>
<html data-require="math math-format polynomials graphie derivative-intuition">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Derivative intuition</title>
<script data-main="../local-only/main" src="../local-only/require.js"></script>
</head>
<body>
<div class="exercise">
<div class="problems">
<div id="polynomial" data-weight="4">
<div class="vars">
<var id="SCENARIO">{}</var>
<var id="POLYNOMIAL">new Polynomial(randRange(0, 3), randRange(2, 4))</var>
<var id="FNXTEXT">POLYNOMIAL.text()</var>
<var id="DDXTEXT">POLYNOMIAL.derivative().text()</var>
<var id="FNX">function(x) {return POLYNOMIAL.evalOf(x);}</var>
<var id="DDX">function(x) {return POLYNOMIAL.derivative().evalOf(x);}</var>
<var id="POINTS">[-2, -1.5, -1, 0, 1, 1.5, 2]</var>
<var id="XRANGE">[-2.5, 2.5]</var>
<var id="YMIN">min.apply(Math, $.map(POINTS, FNX).concat( $.map(POINTS, DDX)))</var>
<var id="YMAX">max.apply(Math, $.map(POINTS, FNX).concat( $.map(POINTS, DDX)))</var>
<var id="YRANGE">[floorTo(-1, YMIN - (YMAX-YMIN)*0.05 ), ceilTo(-1, YMAX + (YMAX-YMIN)*0.05)]</var>
<var id="OPTIONS">{}</var>
</div>
<p class="question">
Drag each one of the <var>POINTS.length</var> <span class="hint_orange">orange</span> points up and down
to adjust the slope of the corresponding tangent line.
</p>
<p>
The derivative of a function is defined as the slope of a line tangent to the curve at each point.
Adjust the slopes of the lines to visually find the derivative <code>\frac{d}{dx} f(x)</code> at each point.
</p>
<div class="problem">
<div class="graphie" id="ddxplot">
initAutoscaledGraph([ XRANGE, YRANGE], OPTIONS);
style({
stroke: "#6495ED",
strokeWidth: 3
}, function() {
plot( function( x ) {
return FNX( x );
}, XRANGE );
});
initDerivativeIntuition(FNX, DDX, POINTS);
</div>
</div>
<p>
<code class="hint_blue">f(x) = <var>FNXTEXT</var></code>
<span id="ddxspan" style="margin-left: 5em; display: none; opacity:0">
<code class="hint_orange">\frac{d}{dx}f(x) = <var>DDXTEXT</var></code>
</span>
</p>
<div class="solution" data-type="custom">
<div class="instruction">
<table id="answers">
<tbody><tr data-each="POINTS as X">
<td class="sol" data-fallback="0" style="display: none"><var>roundTo(2, DDX(X))</var></td>
<td data-if="OPTIONS.xLabelFormat" style="text-align: right"><code>\frac{d}{dx} f(<var>OPTIONS.xLabelFormat(X)</var>) = {}</code></td>
<td data-else="" style="text-align: right"><code>\frac{d}{dx} f(<var>X</var>) = {}</code></td>
<td class="answer-label">0</td>
</tr>
</tbody></table>
</div>
<div class="guess">
(function(){
var guess = [];
$("#answers").find('.answer-label').each(function(label) {
guess.push(parseFloat($(this).text()));
});
return guess;
})()
</div>
<div class="validator-function">
var allDefault = _(guess).all(function(x) {
return x === 0;
});
if (allDefault) {
return "";
}
var correct = _(points).map(function(x) {
return roundTo(2, ddx(x));
});
return guess.join() === correct.join();
</div>
<div class="show-guess">
_(guess).each(function(coordY, i) {
setSlope(i, coordY);
});
var correct = _(points).map(function(x) {
return roundTo(2, ddx(x));
});
if (guess.join() === correct.join()) {
revealDerivative(0);
}
</div>
<div class="show-guess-solutionarea">
$("#answers").find('.answer-label').each(function(index, label) {
$(label).text(guess.length ? guess[index] : 0);
});
</div>
</div>
<div class="hints">
<div>
<p>
The orange curve shows the derivative of <code>f(x)</code>. Drag all of the orange points
onto the orange curve. Notice how the tangent lines change as you move the orange dots.
Pay attention to the relationship between the tangent lines and the blue curve.
</p>
<div class="graphie" data-update="ddxplot">
revealDerivative();
</div>
</div>
</div>
</div>
<div id="special" data-type="polynomial">
<div class="vars">
<var id="SCENARIO">randFromArray([
{
text: "\\sin(x)",
ddxtext: "\\cos(x)",
fnx: function(x) { return Math.sin(x); },
ddx: function(x) { return Math.cos(x); },
xrange: [-1.25*Math.PI, 1.25*Math.PI],
yrange: [ -1.25, 1.25 ],
points: [ -1*Math.PI, -3*Math.PI/4, -Math.PI/2, -Math.PI/4, 0, Math.PI/4, Math.PI/2, 3*Math.PI/4, Math.PI ],
options: { xLabelFormat: piFraction }
}, {
text: "\\cos(x)",
ddxtext: "-\\sin(x)",
fnx: function(x) { return Math.cos(x); },
ddx: function(x) { return -Math.sin(x); },
xrange: [-1.25*Math.PI, 1.25*Math.PI],
yrange: [ -1.25, 1.25 ],
points: [ -1*Math.PI, -3*Math.PI/4, -Math.PI/2, -Math.PI/4, 0, Math.PI/4, Math.PI/2, 3*Math.PI/4, Math.PI ],
options: { xLabelFormat: piFraction }
}, {
text: "e^x",
ddxtext: "e^x",
fnx: function(x) { return Math.exp(x, Math.E); },
ddx: function(x) { return Math.exp(x, Math.E); },
xrange: [-5, 5],
yrange: [ -5, 15 ],
points: [ -2, -1, 0, 1, 2 ],
options: {}
}, {
text: "\\ln(x)",
ddxtext: "\\frac{1}{x}",
fnx: function(x) { return Math.log(x); },
ddx: function(x) { return 1/x; },
xrange: [ 0.001, 5 ],
yrange: [ -5, 5 ],
points: [ 0.25, 0.5, 1, 2, 3, 4 ],
options: { range: [ [ -0.25, 4.75 ], [ -5, 5 ] ] }
}
])
</var>
<var id="FNXTEXT">SCENARIO.text</var>
<var id="DDXTEXT">SCENARIO.ddxtext</var>
<var id="FNX">SCENARIO.fnx</var>
<var id="DDX">SCENARIO.ddx</var>
<var id="XRANGE">SCENARIO.xrange</var>
<var id="YRANGE">SCENARIO.yrange</var>
<var id="POINTS">SCENARIO.points</var>
<var id="OPTIONS">SCENARIO.options || {}</var>
</div>
</div>
</div>
</div>
</body>
</html>