голубков 1.2

 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
def sign(x):
return cmp(x, 0)
def norm(x):
return sum(i ** 2 for i in x) ** 0.5
def house(x):
n = len(x)
mu = norm(x)
v = x
if mu != 0:
betta = x[0] + sign(x) * mu
v[1:n] = v[1:n]/betta
v[0] = 1
def rowHouse(a, v):
m = len(v)
vt = np.vstack((v, np.zeros((m-1, m))))
c = np.dot(vt, vt.transpose())
betta = -2/c[0][0]
at = np.hstack((a,np.zeros((m, 1))))
w = np.dot(at.transpose(), vt.transpose()) #что делать с betta?
reducedw = np.hsplit(np.dot(vt.transpose(), w.transpose()), (0,m-1))
a = a + reducedw[1]
def qrColumnPivoting(q, r, p, a):
n = len(a)
m = len(a[0])
for j in range(0, n):
return q, r, p
a = [[1,2,3], [1,5,6], [1,8,9], [1,11,12]]
q, r, p = qrColumnPivoting(np.identity(len(a)), np.array(a), np.identity(len(a[0])), np.array(a))