Versionsvergleich
Aus ProgrammingWiki
Vergleich: 2014-10-19T21:42:17+00:00 → 2014-10-19T21:50:16+00:00
<language>Java</language> | |
<code id="51c2c2c846c5b" hidden> | |
int z1 = 1; int n1 = 1; | |
int z2 = 1; int n2 = 1; | |
int ze = 1; int ne = 1; | |
public void Bruch1(int z, int n) { | |
if (n < 0) { | |
z = -z; n = Math.abs(n); | |
} | |
z1 = z; | |
n1 = n; | |
} | |
public void Bruch2(int z, int n) { | |
if (n < 0) { | |
z = -z; n = Math.abs(n); | |
} | |
z2 = z; | |
n2 = n; | |
} | |
public void Ausgabe() { | |
System.out.println(ze + "/" + ne); | |
} | |
private int ggT(int m, int n) { | |
if (n == 0) | |
return m; | |
else | |
return ggT(n, m % n); | |
} | |
public void Kuerzen(int z, int n) { | |
int teiler = Math.abs(ggT(z, n)); | |
ze = z / teiler; | |
ne = n / teiler; | |
} | |
</code> | |
<p>Gegeben sind die beiden Brüche $b_1=\frac{z_1}{n_1}$ und $b_2=\frac{z_2}{n_2}$</p> | |
<p>mit $z_1, z_2 \in \mathbb{Z}$ ; $n_1, n_2 \in \mathbb{N}$ und $n_1 \not= 0$ ; $n_2 \not= 0$.</p> | |
== Addition und Subtraktion von Brüchen == | |
<table border="0" cellpadding="4"> | |
<tr> | |
<td colspan="2">Allgemein gilt:</td> | |
</tr> | |
<tr> | |
<th>Addition</th><th>Subtraktion</th> | |
</tr> | |
<tr valign="top"> | |
<td> | |
| − | <blockquote>$b_1 + b_2 = \frac{z_1}{n_1} + \frac{z_2}{n_2}$</blockquote> |
| − | <blockquote>$b_1 + b_2 = \frac{z_1 \cdot n_2 + z_2 \cdot n_1}{n_1 \cdot n_2}$</blockquote> |
| + | <blockquote>\[b_1 + b_2 = \frac{z_1}{n_1} + \frac{z_2}{n_2}\]</blockquote> |
| + | <blockquote>\[b_1 + b_2 = \frac{z_1 \cdot n_2 + z_2 \cdot n_1}{n_1 \cdot n_2}\]</blockquote> |
</td> | |
<td> | |
| − | <blockquote>$b_1 - b_2 = \frac{z_1}{n_1} - \frac{z_2}{n_2}$</blockquote> |
| − | <blockquote>$b_1 - b_2 = \frac{z_1 \cdot n_2 - z_2 \cdot n_1}{n_1 \cdot n_2}$</blockquote> |
| + | <blockquote>\[b_1 - b_2 = \frac{z_1}{n_1} - \frac{z_2}{n_2}\]</blockquote> |
| + | <blockquote>\[b_1 - b_2 = \frac{z_1 \cdot n_2 - z_2 \cdot n_1}{n_1 \cdot n_2}\]</blockquote> |
</td> | |
</tr> | |
<tr> | |
<td colspan="2">Natürlich wird das Ergebnis anschließend vollständig gekürzt.</td> | |
</tr> | |
<tr valign="top"> | |
<td> | |
<code id="51c2c2c846cea"> | |
public void Addition() { | |
ze = z1 * n2 + z2 * n1; | |
ne = n1 * n2; | |
Kuerzen(ze, ne); | |
} | |
</code> | |
</td> | |
<td> | |
<code id="51c2c2c846dee"> | |
public void Subtraktion() { | |
ze = z1 * n2 - z2 * n1; | |
ne = n1 * n2; | |
Kuerzen(ze, ne); | |
} | |
</code> | |
</td> | |
</tr> | |
<tr valign="top"> | |
<td> | |
<run id="51c2c2c846fff"> | |
Bruch1(3, 4); | |
Bruch2(2, 3); | |
Addition(); | |
Ausgabe(); | |
</run> | |
</td> | |
<td> | |
<run id="51c2c2c847088"> | |
Bruch1(3, 4); | |
Bruch2(2, 3); | |
Subtraktion(); | |
Ausgabe(); | |
</run> | |
</td> | |
</tr> | |
</table> | |
== Multiplikation und Division von Brüchen == | |
<table border="0" cellpadding="4"> | |
<tr> | |
<td colspan="2">Allgemein gilt:</td> | |
</tr> | |
<tr> | |
<th>Multiplikation</th><th>Division</th> | |
</tr> | |
<tr valign="top"> | |
<td> | |
| − | <blockquote>$b_1 \cdot b_2 = \frac{z_1}{n_1} \cdot \frac{z_2}{n_2}$</blockquote> |
| − | <blockquote>$b_1 \cdot b_2 = \frac{z_1 \cdot z_2}{n_1 \cdot n_2}$</blockquote> |
| + | <blockquote>\[b_1 \cdot b_2 = \frac{z_1}{n_1} \cdot \frac{z_2}{n_2}\]</blockquote> |
| + | <blockquote>\[b_1 \cdot b_2 = \frac{z_1 \cdot z_2}{n_1 \cdot n_2}\]</blockquote> |
</td> | |
<td> | |
| − | <blockquote>$b_1 : b_2 = \frac{z_1}{n_1} : \frac{z_2}{n_2}$</blockquote> |
| − | <blockquote>$b_1 : b_2 = \frac{z_1 \cdot n_2}{n_1 \cdot z_2}$</blockquote> |
| + | <blockquote>\[b_1 : b_2 = \frac{z_1}{n_1} : \frac{z_2}{n_2}\]</blockquote> |
| + | <blockquote>\[b_1 : b_2 = \frac{z_1 \cdot n_2}{n_1 \cdot z_2}\]</blockquote> |
</td> | |
</tr> | |
<tr> | |
<td colspan="2">Auch hier wird das Ergebnis vollständig gekürzt.</td> | |
</tr> | |
<tr valign="top"> | |
<td> | |
<code id="51c2c2c846ed0"> | |
public void Multiplikation() { | |
ze = z1 * z2; | |
ne = n1 * n2; | |
Kuerzen(ze, ne); | |
} | |
</code> | |
</td> | |
<td> | |
<code id="51c2c2c846f59"> | |
public void Division() { | |
ze = z1 * n2; | |
ne = n1 * z2; | |
if (ne < 0) { | |
ze = -ze; ne = Math.abs(ne); | |
} | |
Kuerzen(ze, ne); | |
} | |
</code> | |
</td> | |
</tr> | |
<tr valign="top"> | |
<td> | |
<run id="51c2c2c84710c"> | |
Bruch1(3, 4); | |
Bruch2(2, 3); | |
Multiplikation(); | |
Ausgabe(); | |
</run> | |
</td> | |
<td> | |
<run id="51c2c2c84718e"> | |
Bruch1(3, 4); | |
Bruch2(2, 3); | |
Division(); | |
Ausgabe(); | |
</run> | |
</td> | |
</tr> | |
</table> |