Compare commits

..

No commits in common. "0074722ad321d851264a92fdf9714f20ca0898fe" and "0fb8b74d994ed0ff9413d2e925940b5619b4ee0a" have entirely different histories.

1 changed files with 12 additions and 45 deletions

View File

@ -32,38 +32,23 @@ def Serie8_Aufg2(A):
R = A R = A
for j in np.arange(0,n-1): for j in np.arange(0,n-1):
# erzeuge Nullen in R in der j-ten Spalte unterhalb der Diagonalen: a = np.copy(unknown).reshape(n-j,1)
#a = (Q @ A)[j:,j:][:,0] e = np.eye(unknown)[:,0].reshape(n-j,1)
a = np.copy((Q @ A)[j:,j:][:,0]).reshape(n-j,1)
e = np.eye(n-j)[:,0].reshape(n-j,1)
length_a = np.linalg.norm(a) length_a = np.linalg.norm(a)
if a[0] >= 0: sig = 1 if a[0] >= 0: sig = unknown
else: sig = -1 else: sig = unknown
v = a + sig * length_a * e # vj := aj + sign(a1j) · |aj| · ej v = unknown
u = 1 / np.linalg.norm(v) * v # uj := 1/|vj|*vj u = unknown
ut = u.T H = unknown
ua = u @ ut Qi = np.eye(n)
ub = 2 * ua Qi[j:,j:] = unknown
x = np.eye(n) R = unknown
H = np.eye(n-j) - (2 * (u @ u.T)) # Hj := In 2u1u1T bestimme die (n j + 1) × (n j + 1) Householder-Matrix Hj Q = unknown
Qj = np.eye(n)
Qj[j:,j:] = H # erweitere Hi durch einen Ii1 Block links oben zur n × n Matrix Qi
R = Qj @ R # R := Qj · R
Q = Q @ Qj.T # Q := Q · QjT
return(Q,R) return(Q,R)
if __name__ == '__main__': if __name__ == '__main__':
# Beispiel
# A = np.array([[1, 2, -1], [4, -2, 6], [3, 1, 0]])
# b = np.array([
# [9],
# [-4],
# [9]
# ])
# Example from Task 1
A = np.array([ A = np.array([
[1, -2, 3], [1, -2, 3],
[-5, 4, 1], [-5, 4, 1],
@ -75,22 +60,4 @@ if __name__ == '__main__':
[5] [5]
]) ])
[Q,R]=Serie8_Aufg2(A) Serie8_Aufg2(A)
n = len(b) - 1
QTb = Q.T @ b
result = [0 for i in range(n+1)]
row = n
while row >= 0:
value = QTb[row][0]
column = n
while column > row:
value -= R[row][column] * result[column]
column -= 1
value = value / R[row,row]
result[row] = value
row -= 1
print("\nQ:\n", Q)
print("\nR:\n", R)
print("\Result:\n", result)