Compare commits
10
Commits
ee463720d9
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d2c1d957e8 | ||
|
|
ca306c728b | ||
|
|
fc3bbc49cc | ||
|
|
d364086bb1 | ||
|
|
9534795504 | ||
|
|
66754eebc5 | ||
|
|
e1f9d06b35 | ||
|
|
ea59d8ab22 | ||
|
|
388773f989 | ||
|
|
1638ceadcb |
@@ -160,3 +160,4 @@ cython_debug/
|
||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
#.idea/
|
||||
|
||||
/Leo_2.py
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -6,66 +6,74 @@ xmin = 1.99
|
||||
xmax = 2.01
|
||||
x_number_of_points = 500
|
||||
xsteps = (xmax - xmin) / x_number_of_points
|
||||
|
||||
|
||||
def f1(x):
|
||||
return x ** 7 - 14 * x ** 6 + 84 * x ** 5 - 280 * x ** 4 + 560 * x ** 3 - 672 * x ** 2 + 448 * x - 128
|
||||
|
||||
|
||||
def f2(x):
|
||||
return (x - 2) ** 7
|
||||
|
||||
|
||||
x1 = np.arange(xmin, xmax + xsteps, xsteps)
|
||||
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))
|
||||
plt.plot(x1, yf1)
|
||||
plt.plot(x1, yf2)
|
||||
plt.legend(["f1(x)", "f2(x)"])
|
||||
|
||||
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
|
||||
# zwischengespeichert werden. In den zwei Funktionen f1 und f2 werden die
|
||||
# Rechenoperationen in einer anderen Reihenfolge ausgeführt.
|
||||
# bei f1 werden die Terme addiert. Entsprechend ist beim Runden nur der Termin mit dem
|
||||
# grössten Exponent dominant.
|
||||
# bei f2 erhält man immer eine Zahl nahe bei 0.
|
||||
# bei f1 werden die Terme addiert. Damit werden die Rundungsfehler Kummuliert.
|
||||
# bei f2 erhält man immer eine Zahl nahe bei 0 da nur eine Subtraktion durchgeführt
|
||||
# wird die einen zu einem Rundungsfehler führen kann.
|
||||
|
||||
# Aufgabe 2b
|
||||
xmin = -10 ** -14
|
||||
xmax = 10 ** -14
|
||||
xsteps = 10 ** -17
|
||||
|
||||
|
||||
def g1(x):
|
||||
return x / (np.sin(1 + x) - np.sin(1))
|
||||
|
||||
|
||||
x2 = np.arange(xmin, xmax + xsteps, xsteps)
|
||||
yg1 = np.array([])
|
||||
for x_value in x2:
|
||||
yg1 = np.append(yg1, g1(x_value))
|
||||
plt.plot(x2, yg1)
|
||||
print("min g1: ", min(yg1), "max g1: ", max(yg1))
|
||||
yg1 = [g1(x_value) for x_value in x2]
|
||||
plt.plot(x2, yg1, label='g1(x)')
|
||||
print(f'min g1: {min(yg1)} max g1: {max(yg1)}')
|
||||
|
||||
|
||||
# Die Berechnung des Grenzwertes für x --> 0 g(x) ist nicht stabil.
|
||||
# Der Grenzwert scheint unendlich gross / klein zu sein.
|
||||
# Bei g1 ist der Nenner sehr gross wenn x --> 0.
|
||||
|
||||
# Aufgabe 2c
|
||||
# a = 1+x, b = 1
|
||||
def g2(x):
|
||||
return x / (2 * np.cos((1 + x + 1) / 2) * np.sin((x) / 2))
|
||||
yg2 = np.array([])
|
||||
for x_value in x2:
|
||||
yg2 = np.append(yg2, g2(x_value))
|
||||
plt.plot(x2, yg2)
|
||||
print("min g2: ", min(yg2), "max g2: ", max(yg2))
|
||||
plt.legend(["g1(x)", "g2(x)"])
|
||||
|
||||
|
||||
yg2 = [g2(x_value) for x_value in x2]
|
||||
|
||||
plt.plot(x2, yg2, label='g2(x)')
|
||||
|
||||
print(f'min g2: {min(yg2)} max g2: {max(yg2)}')
|
||||
plt.legend()
|
||||
plt.title("Aufgabe 2bc")
|
||||
|
||||
# Der Grenzwert für x = 0 beträgt 1.85. Die Funktion ist nun stabil. Bei g1 ist der Nenner 0 wenn x = 0
|
||||
# Bei der Funktion g2 bleibt der Wert stabil bei 1.85.
|
||||
# Die Auslöschung kann vermieden werden, Wenn X gegen 0 geht wurde der Nenner sehr gross.
|
||||
# Bei der Funktion g2 bleibt der Wert stabil bei 1.85. Somit ist dies der Grenzwert.
|
||||
# Die Auslöschung kann vermieden werden indem Sinus und Cosinus im Nenner stehen.
|
||||
|
||||
|
||||
plt.show()
|
||||
|
||||
|
||||
|
||||
@@ -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 = int(1) #Radius
|
||||
n = int(6) #Anzahl Ecken
|
||||
|
||||
r = 1 # Radius
|
||||
n = 6 # Anzahl Ecken
|
||||
sn = r
|
||||
sn_new = r
|
||||
x = np.array([])
|
||||
@@ -19,7 +22,7 @@ for i in range(50):
|
||||
sum_s_new = sn_new * n
|
||||
pi2 = sum_s
|
||||
pi2_new = sum_s_new
|
||||
print("n: ", n, " sn: ", sn_new, " pi: ", pi2)
|
||||
print(f'n: {n} sn: {sn_new} pi: {pi2}')
|
||||
x = np.append(x, n)
|
||||
y = np.append(y, pi2)
|
||||
y_new = np.append(y_new, pi2_new)
|
||||
@@ -28,17 +31,17 @@ for i in range(50):
|
||||
sn = s2n(sn)
|
||||
sn_new = s2n_new(sn_new)
|
||||
|
||||
|
||||
|
||||
plt.plot(x, y)
|
||||
plt.plot(x, y_new)
|
||||
plt.plot(x, y, label='2*pi')
|
||||
plt.plot(x, y_new, label='2*pi_new')
|
||||
plt.xscale('log', base=2)
|
||||
plt.xlim((2 ** 3, 2 ** 31))
|
||||
plt.ylim((6.25, 6.3))
|
||||
plt.legend(["pi", "pi_new"])
|
||||
plt.legend()
|
||||
|
||||
plt.title("Aufgabe 3")
|
||||
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.
|
||||
# mit der zweiten Formel tritt der Fehler nicht auf.
|
||||
# Durch Rundungsfehler steigt der Wert fälschlicherweise an und fällt anschliessend durch
|
||||
# Auslöschung auf 0.
|
||||
# mit der zweiten Formel tritt der Fehler nicht auf und der Wert nähert sich an 2*pi
|
||||
|
||||
@@ -1,8 +1,36 @@
|
||||
def maxPower(base):
|
||||
x = 0.5
|
||||
power = 0
|
||||
while x > 0:
|
||||
power = power + 1
|
||||
x = x / base
|
||||
return power
|
||||
print(maxPower(2))
|
||||
|
||||
def eps(base, n): # n = Anzahl Stellen der Mantisse
|
||||
return 0.5 * (base ** (1-n))
|
||||
|
||||
|
||||
def bitsMantiss(base):
|
||||
last_x = 0
|
||||
x = 1.5
|
||||
n = 0
|
||||
while x > 1:
|
||||
last_x = x
|
||||
x = x - (x - 1) / base
|
||||
n = n + 1
|
||||
return n, last_x
|
||||
|
||||
def largestNumber(bitsMantiss):
|
||||
x = 0.0
|
||||
for i in range(bitsMantiss):
|
||||
x = x + 2 ** i
|
||||
return x
|
||||
|
||||
def largestNumber_eps(eps, n):
|
||||
return eps * 2**(2*n) - 1
|
||||
|
||||
|
||||
bitsMan = bitsMantiss(2)
|
||||
epsVal = eps(2, bitsMan[0])
|
||||
largest = largestNumber(bitsMan[0])
|
||||
largest_eps = largestNumber_eps(epsVal, bitsMan[0])
|
||||
|
||||
|
||||
print(f'eps: {epsVal}')
|
||||
print(f'Bits Mantiss: {bitsMan[0]}')
|
||||
print(f'Smallest Number 1 + eps > 1: {bitsMan[1]}')
|
||||
print(f'largest Number 1 + qmax > qmax: {largest}')
|
||||
print(f'largest Number 1 + qmax > qmax (calculated by eps: {largest_eps}')
|
||||
Reference in New Issue
Block a user