Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- A = np.array([[2,-1,0,0,0,0,0,0,0,0],
- [-1,2,-1,0,0,0,0,0,0,0],
- [0,-1,2,-1,0,0,0,0,0,0],
- [0,0,-1,2,-1,0,0,0,0,0],
- [0,0,0,-1,2,-1,0,0,0,0],
- [0,0,0,0,-1,2,-1,0,0,0],
- [0,0,0,0,0,-1,2,-1,0,0],
- [0,0,0,0,0,0,-1,2,-1,0],
- [0,0,0,0,0,0,0,-1,2,-1],
- [0,0,0,0,0,0,0,0,-1,2]])
- B = np.array([[1,0,0,0,0,0,0,0,0,0],
- [1,1,0,0,0,0,0,0,0,0],
- [1,1,1,0,0,0,0,0,0,0],
- [1,1,1,1,0,0,0,0,0,0],
- [1,1,1,1,1,0,0,0,0,0],
- [1,1,1,1,1,1,0,0,0,0],
- [1,1,1,1,1,1,1,0,0,0],
- [1,1,1,1,1,1,1,1,0,0],
- [1,1,1,1,1,1,1,1,1,0],
- [1,1,1,1,1,1,1,1,1,1]])
- q = np.array([1,1,1,1,1,1,1,1,1,1]).reshape((10,1))
- d = np.array([1,2,3,4,5,6,7,8,9,10]).reshape((10,1))
- def count_x(lam):
- #x = A^-1(q-(lam^T*B)^T)/2
- x = np.linalg.inv(A)
- x = x.dot(q - np.dot(B.T, lam))
- return x / 2
- def count_lam(x, lam, r):
- #lami = lami + r(fi(x))
- lam = lam + r * (np.dot(B, x) - d)
- lam = np.maximum(np.array([0,0,0,0,0,0,0,0,0,0]).reshape((10,1)), lam)
- return lam
- def Problem(r=1, eps=0.01):
- x = np.array([0,0,0,0,0,0,0,0,0,0]).reshape((10,1))
- lam = np.array([1,1,1,1,1,1,1,1,1,1]).reshape((10,1))
- lam = count_lam(x, lam, r)
- x_new = count_x(lam)
- #print (x_new)
- #print(x)
- #print(np.linalg.norm(x - x_new))
- while (np.linalg.norm(x - x_new) > eps):
- x = x_new
- lam = count_lam(x, lam, r)
- x_new = count_x(lam)
- return x
- Problem(r=0.0001, eps=0.0000001)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement