HM1_Aufgabenserie2/Schenk_Brandenberger_S2_Auf...

47 lines
1010 B
Python
Raw Normal View History

2022-10-04 14:54:32 +02:00
import numpy as np
import matplotlib.pyplot as plt
2022-10-12 08:16:59 +02:00
2022-10-04 14:54:32 +02:00
def s2n(s1n):
return np.sqrt(2 - 2 * np.sqrt(1 - ((s1n ** 2) / 4)))
2022-10-12 08:16:59 +02:00
2022-10-04 14:54:32 +02:00
def s2n_new(s1n):
return np.sqrt((s1n ** 2) / (2 * (1 + np.sqrt(1 - ((s1n ** 2) / 4)))))
2022-10-12 08:16:59 +02:00
r = 1 # Radius
n = 6 # Anzahl Ecken
2022-10-04 14:54:32 +02:00
sn = r
sn_new = r
x = np.array([])
y = np.array([])
y_new = np.array([])
for i in range(50):
sum_s = sn * n
sum_s_new = sn_new * n
2022-10-07 11:07:47 +02:00
pi2 = sum_s
pi2_new = sum_s_new
print("n: ", n, " sn: ", sn_new, " pi: ", pi2)
2022-10-04 14:54:32 +02:00
x = np.append(x, n)
2022-10-07 11:07:47 +02:00
y = np.append(y, pi2)
y_new = np.append(y_new, pi2_new)
2022-10-04 14:54:32 +02:00
n = n * 2
sn = s2n(sn)
sn_new = s2n_new(sn_new)
plt.plot(x, y)
plt.plot(x, y_new)
plt.xscale('log', base=2)
2022-10-12 08:16:59 +02:00
plt.xlim((2 ** 3, 2 ** 31))
2022-10-07 11:07:47 +02:00
plt.ylim((6.25, 6.3))
2022-10-12 08:16:59 +02:00
plt.legend(["2*pi", "2*pi_new"])
2022-10-07 11:07:47 +02:00
plt.title("Aufgabe 3")
2022-10-04 14:58:09 +02:00
plt.show()
# mit der ersten Formel stimmt der berechnete Wert ab n = 50331648 nicht mehr.
# mit n = 805306368 erhält man für pi 6, danach immer 0.
2022-10-12 08:16:59 +02:00
# mit der zweiten Formel tritt der Fehler nicht auf.