-
Notifications
You must be signed in to change notification settings - Fork 0
/
measuring-energy-changes.html
268 lines (263 loc) · 7.41 KB
/
measuring-energy-changes.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
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
<!DOCTYPE html>
<html>
<head>
<title>Measuring Energy Changes</title>
<meta charset="utf-8">
<link rel="shortcut icon" href="flags_ora_icon.ico">
<link href="https://fonts.googleapis.com/css?family=Quattrocento|Quattrocento Sans|Work Sans" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.4.0/Chart.min.js"></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_CHTML'></script>
<link rel="stylesheet" href="Styles/style3.css">
</head>
<body>
<div id="grid">
<div id="head">
<h1>Measuring Energy Changes</h1>
<h2>Enter your data here:</h2>
</div>
<div id="tempsDiv">
<h2>Temperature of \(H_{2}O\)</h2>
<table id="temps">
<thead><td>Minute</td><td>Temperature (°C)</td></thead>
<tbody id="Btemps"></tbody>
</table>
<table id="buttons">
<tr>
<td class="no"><button onclick = "addmin();">Add Minute</button></td>
<td class="no"><button onclick = "delmin();">Delete Minute</button></td>
</tr>
</table>
</div>
<div id="phasesDiv">
<h2>Times of Phase Changes</h2>
<table id="phases">
<thead><td>Finished Melting</td><td>Started Boiling</td></thead>
<tbody id="Bphases"><td><input type="number" name=""></td><td><input type="number" name=""></td></tbody>
</table>
</div>
<div id="mid">
<p class="error"><br></p>
<div class="center Dbut"><button id="submit-a" onclick="calculateA();">Generate Graph</button></div>
</div>
<div id="Dscatter"><canvas id="scatter"></canvas></div>
<div id="voltempDiv">
<h2>Volume and Temperature of \(H_{2}O\)</h2>
<table id="voltemp">
<thead>
<tr><td></td><td>Initial</td><td>Final</td></tr>
</thead>
<tbody id="Bvoltemp">
<tr><td>Volume (mL)</td><td><input type="number" step="0.01" name=""></td><td><input type="number" step="0.01" name=""></td></tr><tr><td>Temp (°C)</td><td><input type="number" step="0.01" name=""></td><td><input type="number" step="0.01" name=""></td></tr>
</tbody>
</table>
</div>
<div id="calc">
<p class="error"><br></p>
<table>
<td class="no"><button id="calculate-B" onclick="calculateB();">Calculate Data</button></td>
</table>
</div>
<div id="answer">
<h2>Summative Data</h2>
<table>
<thead>
<tr>
<td>Water Mass (g)</td>
<td>Heat Released (J)</td>
<td>Heat Absorbed (J)</td>
<td>Ice Volume (mL)</td>
<td>Ice Mass (g)</td>
<td>Energy Per Gram (J/g)</td>
<td>\(\Delta H_{Fusion}\) (kJ/mol)</td>
<td>Percent Error (%)</td>
</tr>
</thead>
<tbody id="Banswer">
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
</div>
<script type="text/javascript">
var minutes = 20;
var data = [];
var tempsRow = "<td>%d</td><td><input type='number' step='0.01' name=''></td>";
var temps = document.getElementById("Btemps");
var phases= document.getElementById("Bphases");
var AAAnswer = document.getElementById("answer");
var errors = document.getElementsByClassName("error");
var plot = document.getElementById("scatter");
var inB = document.querySelectorAll("#Bvoltemp input");
var ansout = document.querySelectorAll("#Banswer td");
var color = Chart.helpers.color;
for(var i = 0; i <= minutes; i ) {
var n = document.createElement("tr");
n.innerHTML = tempsRow.replace('%d', i);
temps.appendChild(n);
}
//for(var i = 0; )
function addmin() {
minutes ;
var n = document.createElement("tr");
n.innerHTML = tempsRow.replace('%d', minutes);
temps.appendChild(n);
}
function delmin() {
if(minutes <= 0) return;
minutes--;
var n = temps.querySelector("tr:nth-last-of-type(1)");
temps.removeChild(n);
}
var calculateA = function() {
// 0 < solToLiquid < LiquidToGas < minutes
StoL = parseInt(phases.querySelector("td:nth-of-type(1) input").value) || 0;
LtoG = parseInt(phases.querySelector("td:nth-of-type(2) input").value) || 0;
console.log(0 ", " StoL ", " LtoG ", " minutes);
if( (0 >= StoL) || (StoL >= LtoG) || (LtoG >= minutes) ) {
errors[0].innerHTML = "Please provide the state changes";
return;
}else {errors[0].innerHTML = "<br>";}
data = [Array(), Array(), Array()];
tempData = temps.querySelectorAll("tr td:nth-of-type(2) input");
console.log(minutes ", " tempData.length);
for(let i = 0; i < StoL; i ) {
data[0].push({x: i, y: parseFloat(tempData[i].value) || 0});
}
for(let i = StoL; i < LtoG; i ) {
data[1].push({x: i, y: parseFloat(tempData[i].value) || 0});
}
for(let i = LtoG; i <= minutes; i ) {
data[2].push({x: i, y: parseFloat(tempData[i].value) || 0});
}
console.log(data);
makeScatter();
}
var calculateB = function() {
var answers = [];
var vols = [parseFloat(inB[0].value) || 0, parseFloat(inB[1].value) || 0];
var temps= [parseFloat(inB[2].value) || 0, parseFloat(inB[3].value) || 0];
var delT = temps[1] - temps[0];
if(temps[0] < 30.0) {
var densW = 1.00;
}else if(temps[0] < 42.5) {
var densW = 0.992;
}else if(temps[0] < 47.5) {
var densW = 0.990;
}else if(temps[0] < 52.5) {
var densW = 0.988;
}else {
var densW = 0.985;
}
answers[0] = vols[0] * densW;
answers[1] = 4.18 * answers[0] * delT;
answers[2] = -1 * answers[1];
answers[3] = vols[1] - vols[0];
answers[4] = answers[3] * 1.00;
answers[5] = answers[2] / answers[4] || "Error";
if(answers[5] === "Error") {
errors[1].innerHTML = "Please correct the input";
return;
}
answers[6] = ( answers[5] / 1000 ) * 18.015;
answers[7] = (answers[6] - 6.02) / 6.02 * 100;
if(answers.indexOf("Error") !== -1) {
errors[1].innerHTML = "Please correct the input";
return;
}else {
errors[1].innerHTML = "<br>";
}
AAAnswer.style.visibility = "visible";
answers.forEach(function(a,index) {
ansout[index].innerHTML = a.toFixed(3);
})
console.log(densW ", " iceFuse ", " molsIce);
console.log(answers);
}
window.chartColors = {
red: 'rgb(255, 99, 132)',
orange: 'rgb(255, 159, 64)',
yellow: 'rgb(255, 205, 86)',
green: 'rgb(75, 192, 192)',
blue: 'rgb(54, 162, 235)',
purple: 'rgb(153, 102, 255)',
grey: 'rgb(201, 203, 207)'
};
var makeScatter = function() {
plot.style.visibility = "visible";
var scatterChart = new Chart(plot, {
type: "scatter",
data: {
datasets: [{
label: "Solid",
data: data[0],
backgroundColor: color(window.chartColors.red).alpha(0.2).rgbString(),
borderColor: window.chartColors.red,
fill: false,
showLine: false
},{
label: "Liquid",
data: data[1],
backgroundColor: color(window.chartColors.green).alpha(0.2).rgbString(),
borderColor: window.chartColors.green,
fill: false,
showLine: false
},{
label: "Gas",
data: data[2],
backgroundColor: color(window.chartColors.blue).alpha(0.2).rgbString(),
borderColor: window.chartColors.blue,
fill: false,
showLine: false
}]
},
options: {
scales: {
xAxes: [{
type: "linear",
position: "bottom",
scaleLabel: {
display: true,
labelString: "Minutes Since Heating (min)"
}
}],
yAxes: [{
position: "left",
scaleLabel: {
display: true,
labelString: "Degrees Celsius (°C)"
}
}]
},
title: {
display: true,
position: "top",
fontSize: 18,
fontFamily: "'Quattrocento Sans', sans-serif",
padding: 10,
text: "Temperature of Water At Different States"
},
layout: {
padding: {
left: 20,
right: 20,
top: 20,
bottom: 20
}
}
}
});
plot.style.borderColor = "#ff0";
plot.style.backgroundColor = "#fff";
//MathJax.Hub.Queue(["Typeset",MathJax.Hub,plot]);
}
</script>
</body>
</html>