Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- A = np.asarray([
- [2, 1],
- [-0.5, 1],
- [-6, 1]
- ])
- b = np.asarray([-1,1,-2])
- def line(i, x):
- return (-b[i] + x*A[i,0])/A[i,1]
- if __name__ == "__main__":
- x0 = -1
- x1 = 2
- plt.plot([x0, x1], [line(0,x0), line(0,x1)])
- plt.plot([x0, x1], [line(1,x0), line(1,x1)])
- plt.plot([x0, x1], [line(2,x0), line(2,x1)])
- p_hat = np.dot(np.linalg.inv(np.dot(A.T,A)), np.dot(A.T, b))
- plt.scatter(p_hat[0], p_hat[1])
- plt.xlim(-3,3)
- plt.ylim(-3,3)
- plt.gca().set_aspect('equal')
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement