Compare commits
17
Commits
12a91d3e05
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d2c1d957e8 | ||
|
|
ca306c728b | ||
|
|
fc3bbc49cc | ||
|
|
d364086bb1 | ||
|
|
9534795504 | ||
|
|
66754eebc5 | ||
|
|
e1f9d06b35 | ||
|
|
ea59d8ab22 | ||
|
|
388773f989 | ||
|
|
1638ceadcb | ||
|
|
ee463720d9 | ||
|
|
14704d5cc6 | ||
|
|
d39a7cc4d2 | ||
|
|
5991cc7a13 | ||
|
|
9b6be2f99d | ||
|
|
bd928b6a3a | ||
|
|
f60b666cbf |
@@ -160,3 +160,4 @@ cython_debug/
|
|||||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
#.idea/
|
#.idea/
|
||||||
|
|
||||||
|
/Leo_2.py
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -6,22 +6,74 @@ xmin = 1.99
|
|||||||
xmax = 2.01
|
xmax = 2.01
|
||||||
x_number_of_points = 500
|
x_number_of_points = 500
|
||||||
xsteps = (xmax - xmin) / x_number_of_points
|
xsteps = (xmax - xmin) / x_number_of_points
|
||||||
def f(x):
|
|
||||||
return x ** 7 - 14 * x ** 6 + 84 * x ** 5 - 280 * x ** 4 + 560 * x ** 3 - 672 * x ** 2 + 448 * x - 128
|
|
||||||
def g(x):
|
|
||||||
return (x - 2) ** 7
|
|
||||||
x = np.arange(xmin, xmax + xsteps, xsteps)
|
|
||||||
yf = np.array([])
|
|
||||||
yg = np.array([])
|
|
||||||
for x_value in x:
|
|
||||||
yf = np.append(yf, f(x_value))
|
|
||||||
yg = np.append(yg, g(x_value))
|
|
||||||
plt.plot(x, yf)
|
|
||||||
plt.plot(x, yg)
|
|
||||||
plt.show()
|
|
||||||
print("min f: ", min(yf), "max f: ", max(yf))
|
|
||||||
print("min g: ", min(yg), "max g: ", max(yg))
|
|
||||||
|
|
||||||
#Die Werte sind sehr klein (von e-14 bis e-12)
|
|
||||||
|
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 = [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(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
|
# sodass Rundungsfehler entstehen wenn die Werte als Fliesskommazahlen
|
||||||
# zwischengespeichert werden.
|
# zwischengespeichert werden. In den zwei Funktionen f1 und f2 werden die
|
||||||
|
# Rechenoperationen in einer anderen Reihenfolge ausgeführt.
|
||||||
|
# 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 = [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 = [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")
|
||||||
|
|
||||||
|
# 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()
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
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
|
||||||
|
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
|
||||||
|
pi2 = sum_s
|
||||||
|
pi2_new = sum_s_new
|
||||||
|
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)
|
||||||
|
|
||||||
|
n = n * 2
|
||||||
|
sn = s2n(sn)
|
||||||
|
sn_new = s2n_new(sn_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()
|
||||||
|
|
||||||
|
plt.title("Aufgabe 3")
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
# mit der ersten Formel stimmt der berechnete Wert ab n = 50331648 nicht mehr.
|
||||||
|
# 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
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
|
||||||
|
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