code improvement implemented

This commit is contained in:
leobr 2022-10-12 08:16:59 +02:00
parent ea59d8ab22
commit 66754eebc5
2 changed files with 20 additions and 28 deletions

View File

@ -18,21 +18,17 @@ def f2(x):
x1 = np.arange(xmin, xmax + xsteps, xsteps)
#todo yf1 = [f1(x_value) for x_value in x1]
#todo yf2 = [f2(x_value) for x_value in x1]
yf1 = np.array([])
yf2 = np.array([])
for x_value in x1:
yf1 = np.append(yf1, f1(x_value))
yf2 = np.append(yf2, f2(x_value))
yf1 = [f1(x_value) for x_value in x1]
yf2 = [f2(x_value) for x_value in x1]
plt.plot(x1, yf1, label='f1(x)')
plt.plot(x1, yf2, label='f2(x)')
plt.legend()
plt.title("Aufgabe 2a")
plt.figure()
print("min f1: ", min(yf1), "max f1: ", max(yf1))
print("min f2: ", min(yf2), "max f2: ", max(yf2))
print(f'min f1: {min(yf1)} max f1: {max(yf1)}')
print(f'min f2: {min(yf2)} max f2: {max(yf2)}')
# Die Werte sind sehr klein (von -e-14 bis e-14)
# sodass Rundungsfehler entstehen wenn die Werte als Fliesskommazahlen
@ -53,13 +49,9 @@ def g1(x):
x2 = np.arange(xmin, xmax + xsteps, xsteps)
# todo yg1 = [g1(x_value) for x_value in x2] ?
yg1 = np.array([])
for x_value in x2:
yg1 = np.append(yg1, g1(x_value))
yg1 = [g1(x_value) for x_value in x2]
plt.plot(x2, yg1, label='g1(x)')
#todo print(f'min g1: {min(yg1)} max g1: {max(yg1)}')
print("min g1: ", min(yg1), "max g1: ", max(yg1))
print(f'min g1: {min(yg1)} max g1: {max(yg1)}')
# Die Berechnung des Grenzwertes für x --> 0 g(x) ist nicht stabil.
@ -70,14 +62,12 @@ print("min g1: ", min(yg1), "max g1: ", max(yg1))
def g2(x):
return x / (2 * np.cos((1 + x + 1) / 2) * np.sin((x) / 2))
#todo yg2 = [g2(x_value) for x_value in x2]
yg2 = np.array([])
for x_value in x2:
yg2 = np.append(yg2, g2(x_value))
yg2 = [g2(x_value) for x_value in x2]
plt.plot(x2, yg2, label='g2(x)')
#todo print(f'min g2: {min(yg2)} max g2: {max(yg2)}')
print("min g2: ", min(yg2), "max g2: ", max(yg2))
print(f'min g2: {min(yg2)} max g2: {max(yg2)}')
plt.legend()
plt.title("Aufgabe 2bc")

View File

@ -1,14 +1,17 @@
import numpy as np
import matplotlib.pyplot as plt
def s2n(s1n):
return np.sqrt(2 - 2 * np.sqrt(1 - ((s1n ** 2) / 4)))
def s2n_new(s1n):
return np.sqrt((s1n ** 2) / (2 * (1 + np.sqrt(1 - ((s1n ** 2) / 4)))))
r = 1 #Radius
n = 6 #Anzahl Ecken
r = 1 # Radius
n = 6 # Anzahl Ecken
sn = r
sn_new = r
x = np.array([])
@ -28,14 +31,13 @@ for i in range(50):
sn = s2n(sn)
sn_new = s2n_new(sn_new)
plt.plot(x, y)
plt.plot(x, y_new)
plt.xscale('log', base=2)
plt.xlim((2**3, 2**31))
plt.legend(["2*pi", "2*pi_new"])
plt.xlim((2 ** 3, 2 ** 31))
plt.ylim((6.25, 6.3))
plt.legend(["2*pi", "2*pi_new"])
plt.title("Aufgabe 3")
plt.show()