• API
• FAQ
• Tools
• Archive
SHARE
TWEET # Untitled a guest Oct 18th, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
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,m.sqrt(C[0,0])))
27. print('b = %f +/- %f ' % (P,m.sqrt(C[1,1])))
28. print('c = %f +/- %f ' % (P,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 + P*np.cos(xx) + P*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')
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.

Top