Compare commits

...

4 Commits

Author SHA1 Message Date
schrom01 cd88f40805 Solved Task 3 2022-11-17 18:41:15 +01:00
schrom01 3f4275b81f Solved Task 3 2022-11-14 23:51:31 +01:00
schrom01 634bb99714 Solved Task 2 2022-11-14 23:06:28 +01:00
schrom01 f3ee0390aa Solved Task 2 2022-11-14 23:06:06 +01:00
4 changed files with 70 additions and 3 deletions

View File

@ -31,8 +31,7 @@ def Schenk_Brandenberger_S6_Aufg2(A, b):
countRowSwitch += 1
else:
A, b = calculateRow(A, b, row, column)
print("\nObere Dreiecksmatrix A:\n", A, "\nb:\n", b)
#print("\nObere Dreiecksmatrix A:\n", A, "\nb:\n", b)
# Rückwärtseinsetzen
columnsToEdit = []
@ -41,7 +40,7 @@ def Schenk_Brandenberger_S6_Aufg2(A, b):
for column in columnsToEdit:
A, b = calculateRow(A, b, row, column)
row -= 1
print("\nA:\n", A, "\nb:\n", b)
#print("\nA:\n", A, "\nb:\n", b)
det = 1
result = []

Binary file not shown.

View File

@ -0,0 +1,16 @@
import numpy as np
import scipy
if __name__ == '__main__':
# Aufgabe 2c
A = np.array([[0.8, 2.2, 3.6],
[2.0, 3.0, 4.0],
[1.2, 2.0, 5.8]])
b = np.array([[2.4],
[1.0],
[4.0]])
p, l, u = scipy.linalg.lu(A)
print("\np:\n", p, "\nl:\n", l, "\nu:\n", u)

View File

@ -0,0 +1,52 @@
from Schenk_Brandenberger_S7_Aufg1 import Schenk_Brandenberger_S6_Aufg2
import numpy as np
import matplotlib.pyplot as plt
if __name__ == '__main__':
# Aufgabe 3a
x_plt_label_offset = 1997
x = np.array([0, 2, 9, 13])
y = np.array([150, 104, 172, 152])
A = np.array([
[x[0]**3, x[0]**2, x[0]**1, x[0]**0],
[x[1]**3, x[1]**2, x[1]**1, x[1]**0],
[x[2]**3, x[2]**2, x[2]**1, x[2]**0],
[x[3]**3, x[3]**2, x[3]**1, x[3]**0]])
b = np.array([
[y[0]],
[y[1]],
[y[2]],
[y[3]]])
p1 = Schenk_Brandenberger_S6_Aufg2(A, b)[0]
x_plt1_min = np.min(x)
x_plt1_max = np.max(x)
x_plt1_steps = (float(x_plt1_max) - float(x_plt1_min)) / 100.0
x_plt = np.arange(x_plt1_min, x_plt1_max + x_plt1_steps, x_plt1_steps)
plt.plot(x_plt + x_plt_label_offset, np.polyval(p1, x_plt), label="Aufgabe 3a")
# Aufgabe 3b
print("Schätzwert Aufgabe 3b für das Jahr 2003:", np.polyval(p1, 2003 - x_plt_label_offset))
print("Schätzwert Aufgabe 3b für das Jahr 2004:", np.polyval(p1, 2004 - x_plt_label_offset))
print()
# Aufgabe 3c
p2 = np.polyfit(x, y, 3)
x_plt2_min = np.min(x)
x_plt2_max = np.max(x)
x_plt2_steps = (float(x_plt2_max) - float(x_plt2_min)) / 100.0
x_plt = np.arange(x_plt2_min, x_plt2_max + x_plt2_steps, x_plt2_steps)
plt.plot(x_plt + x_plt_label_offset, np.polyval(p2, x_plt), label="Aufgabe 3c")
print("Schätzwert Aufgabe 3c für das Jahr 2003:", np.polyval(p2, 2003 - x_plt_label_offset))
print("Schätzwert Aufgabe 3c für das Jahr 2004:", np.polyval(p2, 2004 - x_plt_label_offset))
# Plots anzeigen
plt.title("Aufgabe 3")
plt.grid()
plt.legend()
plt.show()