-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtable.js
More file actions
executable file
·80 lines (76 loc) · 2.52 KB
/
table.js
File metadata and controls
executable file
·80 lines (76 loc) · 2.52 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
/**
* Tabulates solution data.
*
* @param objectOfInputs An object containing all the form parameters.
* @param headings Headings for each dependent variable column of the table.
* @return Nothing. Just populates the table with the solution values.
*/
function fillTable(objectOfInputs, headings, solution=undefined) {
// Solve the problem
if (solution == undefined) {
var solution = solveProblem(RKF45, objectOfInputs);
}
if (solution.varsLen() != headings.length) {
alert("libs/common.js#fillTable: vars length and headings length do not match!")
}
var epsilon = objectOfInputs.epsilon;
// Write to table
document.getElementById('tableOutputs').innerHTML = '';
var tableContents = '<table><tr>';
tableContents += '<th>Index</th>';
tableContents += '<th>t (seconds)</th>';
for (let j = 0; j < headings.length ; j++) {
tableContents += '<th>' + headings[j] + '</th>';
}
tableContents += "</tr>";
for (let j = 0; j < solution.tLen(); j++) {
tableContents += '<tr>';
tableContents += '<td>' + j + '</td>';
tableContents += '<td>' + solution.t[j].toFixed(Math.ceil(Math.log10(1/epsilon))) + '</td>';
for (let k = 0; k < solution.varsLen() ; k++) {
tableContents += '<td>' + solution.extract(k)[j].toFixed(Math.ceil(Math.log10(1/epsilon))) + '</td>';
}
tableContents += '</tr>';
}
tableContents += "</table>"
document.getElementById('tableOutputs').innerHTML = tableContents;
}
/**
* Removes the solution table
*
* @params None.
* @return Nothing. Just removes the solution table.
*/
function removeTable() {
// Clear table content
document.getElementById('tableOutputs').innerHTML = '';
}
function generateAllOutputs(objectOfInputs=undefined, solution=undefined) {
if (objectOfInputs==undefined) {
var objectOfInputs = readInputs();
}
if (solution==undefined) {
var solution;
try {
solution = solveProblem(RKF45, objectOfInputs);
} catch(e) {
solution = solveProblemSP(objectOfInputs);
}
}
generateTable(objectOfInputs, solution);
generatePlots(objectOfInputs, solution);
try {
generateAnimations(objectOfInputs, solution);
} catch(e) {
generateAnimation(objectOfInputs, solution);
}
}
function removeAllOutputs() {
removeTable();
removePlots();
try {
removeAnimations()
} catch(e) {
removeAnimation();
}
}