def inversedot(m, v): return dot(la.inverse(m), v) n, nn = m.shape if 1: for i in range(n): sys.stdout.write('% ') for j in range(n): if m[i, j] > 0: sys.stdout.write('+ ') elif m[i, j] < 0: sys.stdout.write('- ') else: sys.stdout.write(' ') sys.stdout.write('\n') cyclic = False for i in range(4): for j in range(n - 4, n): if m[i, j] != 0: cyclic = True print '% cyclic:', cyclic if not cyclic: a = zeros((n, 11), Float) for i in range(n): for j in range(max(-5, -i), min(6, n - i)): a[i, j + 5] = m[i, i + j] for i in range(n): sys.stdout.write('% ') for j in range(11): if a[i, j] > 0: sys.stdout.write('+ ') elif a[i, j] < 0: sys.stdout.write('- ') else: sys.stdout.write(' ') sys.stdout.write('\n') al, indx, d = band.bandec(a, 5, 5) print a band.banbks(a, 5, 5, al, indx, v) return v else: #return inversedot_woodbury(m, v) bign = 3 * n a = zeros((bign, 11), Float) u = zeros(bign, Float) for i in range(bign): u[i] = v[i % n] for j in range(-7, 4): a[i, j + 7] = m[i % n, (i + j + 7 * n) % n] #print a if 1: for i in range(bign): sys.stdout.write('% ') for j in range(11): if a[i, j] > 0: sys.stdout.write('+ ') elif a[i, j] < 0: sys.stdout.write('- ') else: sys.stdout.write(' ') sys.stdout.write('\n') #print u al, indx, d = band.bandec(a, 5, 5) band.banbks(a, 5, 5, al, indx, u) #print u return u[n + 2: 2 * n + 2]
def inversedot_woodbury(m, v): a = zeros((n, 11), Float) for i in range(n): for j in range(max(-7, -i), min(4, n - i)): a[i, j + 7] = m[i, i + j] print a al, indx, d = band.bandec(a, 7, 3) VtZ = identity(4, Float) Z = zeros((n, 4), Float) for i in range(4): u = zeros(n, Float) for j in range(4): u[j] = m[j, n - 4 + i] band.banbks(a, 7, 3, al, indx, u) for k in range(n): Z[k, i] = u[k] #Z[:,i] = u for j in range(4): VtZ[j, i] += u[n - 4 + j] print Z print VtZ H = la.inverse(VtZ) print H band.banbks(a, 7, 3, al, indx, v) return(v - dot(Z, dot(H, v[n - 4:])))