Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. npar = 3
  2.  
  3. sigma = 0.5
  4.  
  5. data = 0.5 + 4.*np.cos(theta) + 1.0*np.sin(theta) + 0.5*r.randn(len(theta))
  6.  
  7. theta = np.linspace(0.,2.*np.pi,51)
  8.  
  9. nobs = len(theta)
  10.  
  11. M = np.column_stack([np.ones(nobs), np.cos(theta), np.sin(theta)])
  12.  
  13. MTM = np.dot(M.transpose(),M)
  14. MTMINV = np.linalg.inv(MTM)
  15. MTY = np.dot(M.transpose(),data)
  16.  
  17. P = np.dot(MTMINV,MTY)
  18.  
  19. C = MTMINV * sigma**2
  20.  
  21. Residuals = data - np.dot(M,P)
  22. ChiSq = np.dot(Residuals.transpose(),Residuals)
  23. RMS = m.sqrt(ChiSq/nobs)
  24. print('RMS = %f'%(RMS))
  25.  
  26. print('a = %f +/- %f ' % (P[0],m.sqrt(C[0,0])))
  27. print('b = %f +/- %f ' % (P[1],m.sqrt(C[1,1])))
  28. print('c = %f +/- %f ' % (P[2],m.sqrt(C[2,2])))
  29.  
  30. pl.ion()
  31. pl.plot(theta,data,'o')
  32. xx = np.linspace(0.,2.*np.pi,51)
  33. ModelY = P[0] + P[1]*np.cos(xx) + P[2]*np.sin(xx)
  34. pl.plot(xx,ModelY,'k')
  35. pl.xlabel('Theta')
  36. pl.ylabel('Data')
  37. pl.title('Big Boi Curve')
  38. pl.grid('on')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement