finished Task 4
This commit is contained in:
parent
5eb8cb5797
commit
33d4cf66eb
|
@ -2,17 +2,15 @@ import numpy as np
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
import math
|
import math
|
||||||
|
|
||||||
# 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.
|
|
||||||
|
|
||||||
def h1(x):
|
def h1(x):
|
||||||
try:
|
try:
|
||||||
return math.sqrt(100 * math.pow(x, 2) - 200 * x + 99)
|
return math.sqrt(100 * math.pow(x, 2) - 200 * x + 99)
|
||||||
except:
|
except:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def h2(x):
|
||||||
|
return math.sqrt((10 * x - 9) * (10 * x - 11))
|
||||||
|
|
||||||
def h1_diff(x):
|
def h1_diff(x):
|
||||||
try:
|
try:
|
||||||
return (100 * x - 100) / math.sqrt(100 * math.pow(x, 2) - 200 * x + 99)
|
return (100 * x - 100) / math.sqrt(100 * math.pow(x, 2) - 200 * x + 99)
|
||||||
|
@ -22,11 +20,7 @@ def h1_diff(x):
|
||||||
def h2_diff(x):
|
def h2_diff(x):
|
||||||
return (100 * x - 100) / math.sqrt((10*x-11)*(10*x-9))
|
return (100 * x - 100) / math.sqrt((10*x-11)*(10*x-9))
|
||||||
|
|
||||||
def h2(x):
|
def kondnumb1(x):
|
||||||
return math.sqrt((10 * x - 9) * (10 * x - 11))
|
|
||||||
|
|
||||||
|
|
||||||
def kondnumb(x):
|
|
||||||
try:
|
try:
|
||||||
return (np.abs(h1_diff(x)) * np.abs(x)) / np.abs(h1(x))
|
return (np.abs(h1_diff(x)) * np.abs(x)) / np.abs(h1(x))
|
||||||
except:
|
except:
|
||||||
|
@ -41,23 +35,35 @@ xStart = 1.1
|
||||||
xStop = 1.31
|
xStop = 1.31
|
||||||
|
|
||||||
x = np.arange(xStart, xStop + xStep, xStep)
|
x = np.arange(xStart, xStop + xStep, xStep)
|
||||||
y1 = [h1(x_val) for x_val in x]
|
yh1 = [h1(x_val) for x_val in x]
|
||||||
y2 = [h2(x_val) for x_val in x]
|
yh2 = [h2(x_val) for x_val in x]
|
||||||
|
ykondnumb1 = [kondnumb1(x_val) for x_val in x]
|
||||||
|
ykondnumb2 = [kondnumb2(x_val) for x_val in x]
|
||||||
|
|
||||||
y3 = [kondnumb(x_val) for x_val in x]
|
# Aufgabe 4a)
|
||||||
y4 = [kondnumb2(x_val) for x_val in x]
|
plt.plot(x, yh1, label='h1(x)')
|
||||||
|
plt.plot(x, yh2, label='h2(x)')
|
||||||
|
plt.title("h(x) für Aufgabe 4a")
|
||||||
|
plt.legend()
|
||||||
|
plt.figure()
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
|
||||||
|
# Aufgabe 4b)
|
||||||
|
plt.plot(x, ykondnumb1, label='Konditionszahl')
|
||||||
|
plt.plot(x, ykondnumb2, label='Konditionszahl nach Umformung')
|
||||||
plt.yscale('log', base=10)
|
plt.yscale('log', base=10)
|
||||||
plt.plot(x, y3, label='Konditionszahl')
|
plt.title('Aufgabe 4b)')
|
||||||
plt.plot(x, y4, label='Konditionszahl nach Umformung')
|
|
||||||
plt.title('4.b)')
|
|
||||||
plt.legend()
|
plt.legend()
|
||||||
plt.figure()
|
plt.figure()
|
||||||
|
|
||||||
plt.plot(x, y1, label='h1(x)')
|
# Aufgabe 4c)
|
||||||
plt.plot(x, y2, label='h2(x)')
|
# Die umgeformte Algebraisch umgeformte Funktion h2 ist besser konditioniert.
|
||||||
|
# Für den Audruck in der Wurzel wird genau 0.0 berechnet (bei x = 1.1).
|
||||||
|
# Es entstehen keine Rundungsfehler mehr.
|
||||||
|
|
||||||
plt.legend()
|
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue