SHARE
TWEET

Untitled

a guest Jun 15th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3.  
  4. A = np.asarray([
  5.   [2, 1],
  6.   [-0.5, 1],
  7.   [-6, 1]
  8. ])
  9.  
  10. b = np.asarray([-1,1,-2])
  11.  
  12. def line(i, x):
  13.   return (-b[i] + x*A[i,0])/A[i,1]
  14.  
  15. if __name__ == "__main__":
  16.  
  17.   x0 = -1
  18.   x1 = 2
  19.  
  20.   plt.plot([x0, x1], [line(0,x0), line(0,x1)])
  21.   plt.plot([x0, x1], [line(1,x0), line(1,x1)])
  22.   plt.plot([x0, x1], [line(2,x0), line(2,x1)])
  23.  
  24.   p_hat = np.dot(np.linalg.inv(np.dot(A.T,A)), np.dot(A.T, b))
  25.  
  26.   plt.scatter(p_hat[0], p_hat[1])
  27.   plt.xlim(-3,3)
  28.   plt.ylim(-3,3)
  29.   plt.gca().set_aspect('equal')
  30.   plt.show()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top