Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def Multiplication(low, main, up, vector):
- result_vector = []
- size = len(vector) - 1
- for i in range(0, len(vector)):
- tmp = main[i] * vector[i]
- if i != 0:
- tmp += low[i] * vector[i - 1]
- if i != size:
- tmp += up[i] * vector[i + 1]
- result_vector.append(tmp)
- return result_vector
- def Discrepancy(left, right):
- ttl = 0
- for i in range(0, len(left)):
- ttl += (left[i] - right[i]) ** 2
- return ttl ** 0.5
- class Matrix:
- def __init__(self, Up, Main, Low, F):
- self.up = Up
- self.main = Main
- self.low = Low
- self.f = F
- def Matvec(m, res, mode):
- if not mode:
- global tay
- return list(map(lambda x: x * tay, Multiplication(low=m.low, main=m.main, up=m.up, vector=res)))
- def SI_Solver(m, res0, mode):
- res = res0
- disc = disc0 = Discrepancy(Multiplication(low=m.low, main=m.main, up=m.up, vector=res0), m.f)
- disc_vector = [disc0]
- disc_size = 1
- while (1):
- v = Matvec(m, res, 0)
- disc = Discrepancy(v, m.f)
- disc_vector.append(disc)
- disc_size += 1
- if (disc / disc0 < 1e-4):
- break
- res = list(map(lambda f, x, v: f + x - v, m.f, res, v))
- return [res, disc_vector]
- up = [-1 for x in range(0, 999)] + [0]
- main = [12] + [2.001 for x in range(0, 999)]
- low = [0] + [-1 for x in range(0, 999)]
- F = [1 if x >= 495 and x <= 505 else 0 for x in range(0, 1000)]
- result0 = [0 for x in range(0, 1000)]
- # MPP
- tay = 0.1651512666112257
- mpp = list(map(lambda x: x*tay, m.f))
- m = Matrix(Up=up, Main=main, Low=low, F=mpp)
- answ = SI_Solver(m=m, res0=result0, mode=0)
- print(answ[0])
- print(len(answ[1]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement