Solved Task 2a
This commit is contained in:
parent
0fb8b74d99
commit
896480733c
|
@ -32,32 +32,43 @@ def Serie8_Aufg2(A):
|
||||||
R = A
|
R = A
|
||||||
|
|
||||||
for j in np.arange(0,n-1):
|
for j in np.arange(0,n-1):
|
||||||
a = np.copy(unknown).reshape(n-j,1)
|
# erzeuge Nullen in R in der j-ten Spalte unterhalb der Diagonalen:
|
||||||
e = np.eye(unknown)[:,0].reshape(n-j,1)
|
#a = (Q @ A)[j:,j:][:,0]
|
||||||
|
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 = unknown
|
if a[0] >= 0: sig = 1
|
||||||
else: sig = unknown
|
else: sig = -1
|
||||||
v = unknown
|
v = a + sig * length_a * e # vj := aj + sign(a1j) · |aj| · ej
|
||||||
u = unknown
|
u = 1 / np.linalg.norm(v) * v # uj := 1/|vj|*vj
|
||||||
H = unknown
|
ut = u.T
|
||||||
Qi = np.eye(n)
|
ua = u @ ut
|
||||||
Qi[j:,j:] = unknown
|
ub = 2 * ua
|
||||||
R = unknown
|
x = np.eye(n)
|
||||||
Q = unknown
|
H = np.eye(n-j) - (2 * (u @ u.T)) # Hj := In − 2u1u1T bestimme die (n − j + 1) × (n − j + 1) Householder-Matrix Hj
|
||||||
|
Qj = np.eye(n)
|
||||||
|
Qj[j:,j:] = H # erweitere Hi durch einen Ii−1 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__':
|
||||||
A = np.array([
|
A = np.array([[1, 2, -1], [4, -2, 6], [3, 1, 0]])
|
||||||
[1, -2, 3],
|
|
||||||
[-5, 4, 1],
|
|
||||||
[2, -1, 3]
|
|
||||||
])
|
|
||||||
b = np.array([
|
|
||||||
[1],
|
|
||||||
[9],
|
|
||||||
[5]
|
|
||||||
])
|
|
||||||
|
|
||||||
Serie8_Aufg2(A)
|
# Example from Task 1
|
||||||
|
# A = np.array([
|
||||||
|
# [1, -2, 3],
|
||||||
|
# [-5, 4, 1],
|
||||||
|
# [2, -1, 3]
|
||||||
|
# ])
|
||||||
|
# b = np.array([
|
||||||
|
# [1],
|
||||||
|
# [9],
|
||||||
|
# [5]
|
||||||
|
# ])
|
||||||
|
|
||||||
|
[Q,R]=Serie8_Aufg2(A)
|
||||||
|
print("\nQ:\n", Q)
|
||||||
|
print("\nR:\n", R)
|
Loading…
Reference in New Issue