fit multiple parametric curves with scipy

前端 未结 2 912
春和景丽
春和景丽 2021-01-13 14:07

I have a set (at least 3) of curves (xy-data). For each curve the parameters E and T are constant but different. I\'m searching the coefficients a,n and m for the best fit o

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-13 15:12

    thanks Evert for the reply.

    Exactly what I needed to know!!

    I have simplyfied the function as far as possible, as you suggested. However, the task was to find ONE set of A,m,n to fit all curves. So my code look like this:

    import numpy
    import math
    from scipy.optimize import leastsq
    
    #+++++++++++++++++++++++++++++++++++++++++++++
    def fit(x,T,A,n,m):
      return A/(n+1.0)*math.pow(T,(n+1.0))*numpy.power(x,m)
    #+++++++++++++++++++++++++++++++++++++++++++++
    def leastsq_func(params, *args):
      cc=args[0]   #number of curves
      incs=args[1] #number of points 
      x=args[2]
      y=args[3]
      T=args[4:]
    
      A=params[0]
      n=params[1]
      m=params[2]
    
      yfit=numpy.empty(x.shape)
      for i in range(cc):
        v=i*incs
        b=(i+1)*incs
        if b

    Works like clockwork.

    At first I put the Ts in the params0 list and they were modified during iteration leading to nonsense results. Obvious, if you think about it. Afterwards ;-)

    So, Vielen Dank! J.

提交回复
热议问题