-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinteract_dev.html
More file actions
300 lines (262 loc) · 6.78 KB
/
Copy pathinteract_dev.html
File metadata and controls
300 lines (262 loc) · 6.78 KB
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
<!DOCTYPE html>
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>
<title>Interactive Pendulum</title>
<style>
body,select,input { font: 20px Arial; }
math { font-size: 1.5em; }
</style>
</head>
<body onload='Body()'>
<h1>Interactive Pendulum</h1>
<p>
<math>
<mi>a</mi>
<mo>=</mo>
<mfrac>
<mrow>
<mi>G</mi>
<mo>·</mo>
<mi>M</mi>
</mrow>
<msup>
<mi>r</mi>
<mn>2</mn>
</msup>
</mfrac>
</math>
</p>
<p>
<math>
<mi>T</mi>
<mo>=</mo>
<mn>2</mn>
<mo>·</mo>
<mi>π</mi>
<msqrt>
<mfrac>
<mi>L</mi>
<mi>a</mi>
</mfrac>
</msqrt>
</math>
</p>
<p>For a surprise, try selecting "Sun mass", "1 astronomical unit", "1 astronomical unit", and "years", below...</p>
<p>What mass is the source of your gravity?
<select id="gravity" onchange="Update();">
<option value="5.975e+24 kilogramm">Earth mass</option>
<option value="7.36e+22 kilogramm">Moon mass</option>
<option value="1.99e+30 kilogramm">Sun mass</option>
</select>
</p>
<p>
How far from the (assumed point) mass are you?
<select id="radius" onchange="Update();">
<option value="6378000 meter">Earth surface (3963.11 miles)</option>
<option value="1740000 meter">Moon surface (1081.19 miles)</option>
<option value="695000000 meter">Sun surface (431853 miles)</option>
<option value="1 au">1 astronomical unit (92955900 miles)</option>
</select>
</p>
<p>
What is the length of your pendulum?
<select id="length" onchange="Update();">
<option value="6 inch">6 inch</option>
<option value="1 foot">1 foot</option>
<option value="100 foot">100 foot</option>
<option value="1 au">1 astronomical unit</option>
<option value="other">other value with unit --></option>
</select>
<input id="otherlength" onchange="Update();"> :[Length]
</p>
<p>
What unit would you like the period expressed in?
<select id="unit" onchange="Update();">
<option value="seconds">seconds</option>
<option value="minutes">minutes</option>
<option value="hours">hours</option>
<option value="days">days</option>
<option value="years">years</option>
</select>
</p>
<p>
<input type="checkbox" id="show" onchange="Update();"> Show your work!
</p>
<p id='status'>loading database ...</p>
<p id='results'></p>
<script type="text/javascript" src="database_dev.js">
// import the database
// var database=...
</script>
<script type="text/javascript" src="engine_dev.js">
// import the engine
</script>
<script>
function Update()
{
document.getElementById("status").innerHTML = "";
var length;
if (document.getElementById("length").value == "other") {
document.getElementById("otherlength").disabled = false;
// parse input to see if valid length
length = document.getElementById("otherlength").value;
if (! length.match(/[:?]/)) {
var results = RunLine(length + ":[Length]");
if (! results.success) {
document.getElementById("status").innerHTML = results.output;
return;
}
} else {
document.getElementById("status").innerHTML = ": or ? not allowed here";
return;
}
} else {
document.getElementById("otherlength").disabled = true;
length = document.getElementById("length").value;
}
var html = "";
// compute the acceleration to the mass: G M/r^2
var equation = "G " + document.getElementById("gravity").value + " / (" + document.getElementById("radius").value + ")^2 ?";
var results = RunLine(equation);
var accel;
html += "<hr><br><b>" + equation + "</b>";
html += "<br><i>" + (results.success?"success":"failure") + "</i>";
for (var j = 0; j < results.output.length; j++) {
html += "<br>" + results.output[j];
accel = results.output[j].replace(/= /, "");
}
// compute the period of the pendulum: 2 pi sqrt(l/a)
var equation = "2 pi sqrt(" + length + " / (" + accel + ")) ? " + document.getElementById("unit").value;
var results = RunLine(equation);
var period;
html += "<hr><br><b>" + equation + "</b>";
html += "<br><i>" + (results.success?"success":"failure") + "</i>";
for (var j = 0; j < results.output.length; j++) {
html += "<br>" + results.output[j];
period = results.output[j].replace(/= /, "");
}
if (! document.getElementById("show").checked) {
html = "";
}
html += "<hr><br><b> acceleration (a) is: " + accel + "</b>";
html += "<br><b> period (T) is: " + period + "</b>";
// display the demo results
document.getElementById("results").innerHTML = html;
if (period == "1.00043 years") {
document.getElementById("surprise").hidden = false;
} else {
document.getElementById("surprise").hidden = true;
}
}
function Body()
{
document.getElementById("status").style.color = "red";
try {
// load the database
loading = true;
LoadDatabase(database);
loading = false;
Update();
} catch (error) {
document.getElementById("status").innerHTML = error;
return;
}
}
</script>
<hr>
<div id="surprise">
<p>Surprise!</p>
<p>How did we get from Keppler's Third Law of planetary motion:
<math>
<mi>T</mi>
<mo>=</mo>
<mn>2</mn>
<mo>·</mo>
<mi>π</mi>
<msqrt>
<mfrac>
<msup>
<mi>r</mi>
<mn>3</mn>
</msup>
<mrow>
<mi>G</mi>
<mo>·</mo>
<mi>M</mi>
</mrow>
</mfrac>
</msqrt>
</math>
back to the period of a simple pendulum???</p>
<p>We also know:
<math>
<mi>F</mi>
<mo>=</mo>
<mfrac>
<mrow>
<mi>G</mi>
<mo>·</mo>
<mi>M</mi>
<mo>·</mo>
<mi>m</mi>
</mrow>
<msup>
<mi>r</mi>
<mn>2</mn>
</msup>
</mfrac>
</math>
where "M" is the mass of the Sun and "m" is the mass of the Earth.
</p>
<p>And we know:
<math>
<mi>F</mi>
<mo>=</mo>
<mi>m</mi>
<mo>·</mo>
<msub>
<mi>a</mi>
<mi>earth</mi>
</msub>
</math>
</p>
<p>So:
<math>
<msub>
<mi>a</mi>
<mi>earth</mi>
</msub>
<mo>=</mo>
<mfrac>
<mrow>
<mi>G</mi>
<mo>·</mo>
<mi>M</mi>
</mrow>
<msup>
<mi>r</mi>
<mn>2</mn>
</msup>
</mfrac>
</math>
</p>
<p>Giving us:
<math>
<mi>T</mi>
<mo>=</mo>
<mn>2</mn>
<mo>·</mo>
<mi>π</mi>
<msqrt>
<mfrac>
<mi>r</mi>
<mi>a</mi>
</mfrac>
</msqrt>
</math>
</p>
<p>Setting "r" to 1 au (the "length" of our Earth's "pendulum") and "a" to the acceleration experienced on Earth because of the Sun's gravity 1 au away takes care of the rest!!!</p>
</div>
</body>
</html>