Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from scipy import *
- from scipy.optimize import *
- from scipy.optimize import leastsq
- import scipy.io.array_import
- from scipy import gplt
- def fitting():
- def residuals(p, y, x):
- err = y-peval(x,p)
- return err
- def peval(x, p):
- return p[0]*((x+p[2])-1/3*(x+p[2])**2+1/10*(x+p[2])**5)+p[1]
- #return p[0]*(1-exp(-(p[2]*x)**p[4])) + p[1]*(1-exp(-(p[3]*(x))**p[5] ))
- filename=('data.txt')
- data = scipy.io.array_import.read_array(filename)
- y = data[:,1]
- x = data[:,0]
- A_0=-2
- B_0=-1650
- C_0=250
- pname = (['A','B','C'])
- p0 = array([A_0 , B_0, C_0])
- plsq = leastsq(residuals, p0, args=(y, x), maxfev=2000)
- gplt.plot(x,y,x,peval(x,plsq[0]))
- gplt.grid("off")
- print "Final parameters"
- for i in range(len(pname)):
- print "%s = %.4f " % (pname[i], p0[i])
Add Comment
Please, Sign In to add comment