Skip to content

Commit d546d2e

Browse files
committed
styling and wertetabelle
1 parent 1d15564 commit d546d2e

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

Mathematics/Stoffsammlung/LineareGlgnInX.html

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<html lang="de">
33
<head>
44
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
56
<title>Math.js Gleichungsrechner</title>
67
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjs/11.11.0/math.min.js"></script>
78
<!-- Carefully take https://mathjs.org/examples/algebra.js.html as a documentation.-->
@@ -18,7 +19,6 @@
1819
#output {
1920
margin-top: 20px;
2021
padding: 10px;
21-
background: #f4f4f4;
2222
border-radius: 6px;
2323
white-space: pre-wrap;
2424
}
@@ -38,9 +38,11 @@ <h2>Math.js Gleichungsrechner</h2>
3838
<p>Beispiel: <code>2x + 7 = 3x + 8</code></p>
3939

4040
<input type="text" id="equation" placeholder="Gib eine Gleichung ein, z.B. 2x + 7 = 3x + 8" size="40">
41-
<button onclick="calculate()">Berechnen</button>
41+
<button onclick="calculate()">Berechnen</button><br>
42+
<button onclick="wertetabelle()">Wertetabelle</button>
4243

4344
<div id="output"></div>
45+
<div id="wertetabelle"></div>
4446

4547
<script>
4648
function calculate() {
@@ -79,6 +81,36 @@ <h2>Math.js Gleichungsrechner</h2>
7981
output.innerText = "Fehler: " + err.message;
8082
}
8183
}
84+
85+
function round(value){
86+
return math.round(value*1000)/1000;
87+
}
88+
function wertetabelle(){
89+
const input = document.getElementById("equation").value;
90+
const [lhs, rhs] = input.split('=');
91+
const theMathFunction = math.simplify( lhs.toString()).toString();
92+
let stellen = "<table><tr><th>x = </th>";
93+
let werte = "<tr><td>f(x) = </td>";
94+
let stellenPart2 = "<table><tr><th>x = </th>";
95+
let wertePart2 = "<tr><td>f(x) = </td>";
96+
for(i=-12;i<1;i++){
97+
let y0 = "<td>" + round(math.evaluate(theMathFunction, {x: i/2.0})).toString() + "</td>";
98+
let x0 = "<th>" + (i/2.0).toString() + "</th>";
99+
stellen += x0;
100+
werte += y0;
101+
}
102+
for(i=1;i<13;i++){
103+
let y0 = "<td>" + round(math.evaluate(theMathFunction, {x: i/2.0})).toString() + "</td>";
104+
let x0 = "<th>" + (i/2.0).toString() + "</th>";
105+
stellenPart2 += x0;
106+
wertePart2 += y0;
107+
}
108+
stellen += "</tr>\n";
109+
werte += "</tr></table><br>\n";
110+
stellenPart2 += "</tr>\n";
111+
wertePart2 += "</tr></table>\n";
112+
document.getElementById("wertetabelle").innerHTML = stellen + werte + stellenPart2 + wertePart2;
113+
}
82114
</script>
83115
</body>
84116
</html>

Mathematics/Stoffsammlung/styles/math.css

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,27 @@ div {
2020
padding-top:1em;
2121
padding-bottom:1em;
2222
margin:2em;
23+
background: #fef8f8;
2324
}
2425
button, img, .img-lost{
2526
margin-left:1em;
2627
}
2728
input{
2829
margin-right:1em;
2930
}
31+
32+
table, th, td {
33+
border: 2px solid coral;
34+
border-collapse: collapse;
35+
padding: 7px;
36+
}
37+
th{
38+
min-width: 1.5em;
39+
}
40+
th:nth-child(odd), td:nth-child(odd){
41+
background-color: papayawhip;
42+
}
43+
th:nth-child(1), td:nth-child(1){
44+
background-color: sandybrown;
45+
font-weight: bold;
46+
}

0 commit comments

Comments
 (0)