Serie 01
This commit is contained in:
48
Serie01/aufg1.py
Normal file
48
Serie01/aufg1.py
Normal file
@@ -0,0 +1,48 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
a = np.array([0, 1, 2, 3, 4, 5, 6])
|
||||
h = np.array([83, 25, 28, 18, 12, 10, 2])
|
||||
|
||||
n = np.sum(h)
|
||||
|
||||
pmf = h / n
|
||||
|
||||
H_abs = h.cumsum()
|
||||
F_rel = pmf.cumsum()
|
||||
|
||||
plt.figure()
|
||||
plt.bar(a, h)
|
||||
plt.title('Relative Häufigkeit (PMF)')
|
||||
plt.xlabel('Anzahl der Defekte')
|
||||
plt.ylabel('Absolute Häufigkeit')
|
||||
plt.xticks(a)
|
||||
plt.tight_layout()
|
||||
|
||||
plt.figure()
|
||||
plt.bar(a, pmf)
|
||||
plt.title('Relative Häufigkeit (PMF)')
|
||||
plt.xlabel('Anzahl der Defekte')
|
||||
plt.ylabel('Relative Häufigkeit')
|
||||
plt.xticks(a)
|
||||
plt.tight_layout()
|
||||
|
||||
plt.figure()
|
||||
plt.step(a, H_abs, where="post")
|
||||
plt.title("Absolute Verteilungsfunktion (CDF)")
|
||||
plt.xlabel("a_i")
|
||||
plt.ylabel("H_i = Σ h_i")
|
||||
plt.xticks(a)
|
||||
plt.tight_layout()
|
||||
|
||||
# 4) CDF relativa (right-continuous)
|
||||
plt.figure()
|
||||
plt.step(a, F_rel, where="post")
|
||||
plt.title("Relative Verteilungsfunktion (CDF)")
|
||||
plt.xlabel("a_i")
|
||||
plt.ylabel("F_i = Σ P(X=a_i)")
|
||||
plt.xticks(a)
|
||||
plt.ylim(0, 1.05)
|
||||
plt.tight_layout()
|
||||
|
||||
plt.show()
|
||||
31
Serie01/aufg10.py
Normal file
31
Serie01/aufg10.py
Normal file
@@ -0,0 +1,31 @@
|
||||
|
||||
|
||||
x = [2.1, 2.4, 2.8, 3.1, 4.2, 4.9, 5.1, 6.0, 6.4, 7.3,
|
||||
10.8, 12.5, 13.0, 13.7, 14.8, 17.6, 19.6, 23.0, 25.0, 35.2, 39.6]
|
||||
|
||||
#median
|
||||
n = len(x)
|
||||
x_sorted = sorted(x)
|
||||
if n % 2 == 1:
|
||||
median = x_sorted[n // 2]
|
||||
else:
|
||||
median = (x_sorted[n // 2 - 1] + x_sorted[n // 2]) / 2
|
||||
|
||||
print("median"+str(median))
|
||||
|
||||
#mean
|
||||
mean = sum(x) / n
|
||||
print("Mittelwert"+str(mean))
|
||||
|
||||
#standard deviation
|
||||
variance = sum((xi - mean) ** 2 for xi in x) / n
|
||||
std_dev = variance ** 0.5
|
||||
print("Standardabweichung"+str(std_dev))
|
||||
|
||||
|
||||
#korrigierte Standardabweichung
|
||||
corrected_variance = sum((xi - mean) ** 2 for xi in x)
|
||||
corrected_std_dev = (corrected_variance / (n - 1)) ** 0.5
|
||||
|
||||
print("korrigierte Standardabweichung"+str(corrected_std_dev))
|
||||
|
||||
28
Serie01/aufg2.py
Normal file
28
Serie01/aufg2.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
d = np.array([1,0,1,1,2,1,0,0,2,1,1,1,3,0,2,2,1,0,2,3,1,1,2,1,1])
|
||||
x, h = np.unique(d, return_counts=True)
|
||||
fi = h / h.sum()
|
||||
Hi = h.cumsum()
|
||||
Fi = fi.cumsum()
|
||||
|
||||
fig, ax = plt.subplots(2, 1, sharex=True, figsize=(6,6))
|
||||
ax[0].bar(x, h, width=0.2)
|
||||
ax[0].set_title("Geschwister")
|
||||
ax[0].set_ylabel("Absolute Häufigkeit")
|
||||
ax[1].bar(x, fi, width=0.2)
|
||||
ax[1].set_xlabel("Anzahl Geschwister")
|
||||
ax[1].set_ylabel("Relative Häufigkeit")
|
||||
fig.tight_layout()
|
||||
|
||||
fig2, ax2 = plt.subplots(2, 1, sharex=True, figsize=(6,6))
|
||||
ax2[0].step(np.r_[x[0], x], np.r_[0, Hi], where="post")
|
||||
ax2[0].set_title("Geschwister")
|
||||
ax2[0].set_ylabel("Abs. Summenhäufigkeit")
|
||||
ax2[1].step(np.r_[x[0], x], np.r_[0, Fi], where="post")
|
||||
ax2[1].set_xlabel("Anzahl Geschwister")
|
||||
ax2[1].set_ylabel("Rel. Summenhäufigkeit")
|
||||
fig2.tight_layout()
|
||||
|
||||
plt.show()
|
||||
0
Serie01/aufg3.py
Normal file
0
Serie01/aufg3.py
Normal file
19
Serie01/aufg8.py
Normal file
19
Serie01/aufg8.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import numpy as np
|
||||
|
||||
R = np.array([720, 740, 760, 780, 800, 820])
|
||||
A = np.array([19, 24, 26, 27, 10, 5])
|
||||
B = np.array([4, 8, 52, 40, 32, 24])
|
||||
|
||||
def qval(edges, counts, x):
|
||||
cdf = np.cumsum(counts) / counts.sum()
|
||||
i = np.searchsorted(edges, x)
|
||||
if i == 0: return 0.0
|
||||
if i >= len(edges): return 1.0
|
||||
w = edges[1] - edges[0]
|
||||
return cdf[i-1] + (x - edges[i-1]) / w * (cdf[i] - cdf[i-1])
|
||||
|
||||
qa = qval(R, A, 730)
|
||||
qb = qval(R, B, 750)
|
||||
|
||||
print(qa)
|
||||
print(qb)
|
||||
Reference in New Issue
Block a user