2022-10-20 14:27:15 +02:00
|
|
|
import numpy as np
|
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
import math
|
|
|
|
|
2022-10-20 16:25:00 +02:00
|
|
|
# Aufgabe 4a)
|
|
|
|
# Da die Operation nicht gut konditioniert ist, erhält man für den Ausdruck inder Wurzel
|
|
|
|
# bei x = 1.1, -1.4e-14 => ein kleiner Rundungsfehler
|
|
|
|
# Somit kann die Wurzel für diesen x Werte nicht berechnet werden.
|
2022-10-20 15:50:45 +02:00
|
|
|
|
2022-10-20 15:21:02 +02:00
|
|
|
def h1(x):
|
2022-10-20 15:50:45 +02:00
|
|
|
try:
|
|
|
|
return math.sqrt(100 * math.pow(x, 2) - 200 * x + 99)
|
|
|
|
except:
|
|
|
|
return
|
|
|
|
|
2022-10-20 15:30:45 +02:00
|
|
|
def h1_diff(x):
|
2022-10-20 16:22:11 +02:00
|
|
|
return (100 * x - 100) / math.sqrt(100 * math.pow(x, 2) - 200 * x + 99)
|
|
|
|
|
|
|
|
def h2_diff(x):
|
2022-10-20 16:03:19 +02:00
|
|
|
return (100 * x - 100) / math.sqrt((10*x-11)*(10*x-9))
|
2022-10-20 15:50:45 +02:00
|
|
|
|
2022-10-20 15:21:02 +02:00
|
|
|
def h2(x):
|
|
|
|
return math.sqrt((10 * x - 9) * (10 * x - 11))
|
|
|
|
|
2022-10-20 14:55:43 +02:00
|
|
|
|
2022-10-20 15:50:45 +02:00
|
|
|
def kondnumb(x):
|
|
|
|
return (np.abs(h1_diff(x)) * np.abs(x)) / np.abs(h1(x))
|
|
|
|
|
2022-10-20 16:25:00 +02:00
|
|
|
def kondnumb2(x):
|
|
|
|
return (np.abs(h2_diff(x)) * np.abs(x)) / np.abs(h2(x))
|
|
|
|
|
2022-10-20 15:50:45 +02:00
|
|
|
|
|
|
|
xStep = math.pow(10, -7)
|
|
|
|
xStart = 1.1
|
|
|
|
xStop = 1.31
|
2022-10-20 14:44:10 +02:00
|
|
|
|
2022-10-20 15:50:45 +02:00
|
|
|
x = np.arange(xStart, xStop + xStep, xStep)
|
2022-10-20 15:21:02 +02:00
|
|
|
y1 = [h1(x_val) for x_val in x]
|
|
|
|
y2 = [h2(x_val) for x_val in x]
|
2022-10-20 14:44:10 +02:00
|
|
|
|
2022-10-20 16:25:00 +02:00
|
|
|
y3 = [kondnumb(x_val) for x_val in x]
|
|
|
|
y4 = [kondnumb2(x_val) for x_val in x]
|
2022-10-20 15:50:45 +02:00
|
|
|
|
2022-10-20 16:25:00 +02:00
|
|
|
plt.yscale('log', base=10)
|
|
|
|
plt.plot(x, y3, label='Konditionszahl')
|
|
|
|
plt.plot(x, y4, label='Konditionszahl nach Umformung')
|
2022-10-20 15:50:45 +02:00
|
|
|
plt.title('4.b)')
|
|
|
|
plt.legend()
|
|
|
|
plt.figure()
|
|
|
|
|
2022-10-20 15:21:02 +02:00
|
|
|
plt.plot(x, y1, label='h1(x)')
|
|
|
|
plt.plot(x, y2, label='h2(x)')
|
2022-10-20 15:50:45 +02:00
|
|
|
plt.xlim(1.099, 1.101)
|
|
|
|
|
2022-10-20 14:55:43 +02:00
|
|
|
plt.legend()
|
2022-10-20 14:44:10 +02:00
|
|
|
plt.show()
|
2022-10-20 15:21:02 +02:00
|
|
|
|
2022-10-20 16:25:00 +02:00
|
|
|
|