-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathnullraum.py
More file actions
38 lines (26 loc) · 674 Bytes
/
Copy pathnullraum.py
File metadata and controls
38 lines (26 loc) · 674 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import numpy as np
H = np.eye(3)*2
A = np.matrix('1 2 -1; 1 -1 1')
g = np.matrix('0;0;0')
b = np.matrix('-4;2')
n = A.shape[1]
m = A.shape[0]
# print('\nA =', A)
block = np.block([[H, np.transpose(A)],
[A, np.zeros((2,2))]])
x = np.linalg.solve(block, np.block([[-g],[-b]]))
print('\nx =', x)
# Nebenbedingungen testen
print('\nSolver p =', x[0:3])
print('\nA*p = -b =', A*x[0:3])
QT, LSchlangeT = np.linalg.qr(A.T, mode="complete") # q*r = A
Q1T = QT[0:n, 0:m]
Q2T = QT[0:n, m:n]
Q2 = Q2T.T
LT = LSchlangeT[0:m,0:m]
L = LT.T
LInv = L.I
y1 = - LInv * b
y2 = (Q2*H*Q2T).I * -Q2 * (g - H * Q1T * LInv * b)
p = Q1T * y1 + Q2T * y2
print('\nNullraum p =', p)