title: fitting hyperbolic and harmonic functions with curvefit
body: <p>I have a problem working with curvefit function.
  Here I have a code with two functions to work with. 
  The first is an hyperbolic function.
  The second is the same but with one parameter = 1.
  My problem is that the result to fit the first function with curvefit works fine but with the second doesn´t.
  I have a commercial program that generates correct solutions for both respectively. So it is possible to find a solution for the second function (a particular case of the first one as I mentioned above)
  Is there someone that could give me an idea about what I am doing wrong ?
  Thanks !</p>
  
  <p>Here is the code to run:</p>
  
  <pre><code>def hypRegress(ptp,pir):
  
      xData = np.arange(len(ptp))
      yData = pir
  
      xData = np.array(xData, dtype=float)
      yData = np.array(yData, dtype= float)
  
      def funcHyp(x, qi, exp, di):
          return qi*(1+exp*di*x)**(-1/exp)
  
      def errfuncHyp(p):
          return funcHyp(xData, p[0], p[1], p[2]) - yData
  
      #print(xData.min(), xData.max())
      #print(yData.min(), yData.max())
  
      trialX = np.linspace(xData[0], xData[-1], 1000)
  
  
  
      # Fit an hyperbolic
      popt, pcov = optimize.curve_fit(funcHyp, xData, yData)
      print 'popt'
      #print(popt)
      yHYP = funcHyp(trialX, *popt)
  
      #optimization
  
      # initial values
      p1, success = optimize.leastsq(errfuncHyp, popt,maxfev=10000)
      print p1
  
      aaaa = funcHyp(trialX, *p1)
  
      plt.figure()
      plt.plot(xData, yData, 'r+', label='Data', marker='o')
      plt.plot(trialX, yHYP, 'r-',ls='--', label="Hyp Fit")
      plt.plot(trialX, aaaa, 'y', label = 'Optimized')
      plt.legend()
      plt.show(block=False)
      return p1
  
  
  def harRegress(ptp,pir):
  
      xData = np.arange(len(ptp))
      yData = pir
  
      xData = np.array(xData, dtype=float)
      yData = np.array(yData, dtype=float)
  
      def funcHar(x, qi, di):
          return qi*(1+di*x)**(-1)
  
      def errfuncHar(p):
          return funcHar(xData, p[0], p[1]) - yData
  
      #print(xData.min(), xData.max())
      #print(yData.min(), yData.max())
  
      trialX = np.linspace(xData[0], xData[-1], 1000)
  
  
  
      # Fit an harmonic
      popt, pcov = optimize.curve_fit(funcHar, xData, yData)
      print 'popt'
      print(popt)
      yHAR = funcHar(trialX, *popt)
  
      #optimization
  
      # initial values
      p1, success = optimize.leastsq(errfuncHar, popt,maxfev=1000)
      print p1
  
      aaaa = funcHar(trialX, *p1)
  
      plt.figure()
      plt.plot(xData, yData, 'r+', label='Data', marker='o')
      plt.plot(trialX, yHAR, 'r-',ls='--', label="Har Fit")
      plt.plot(trialX, aaaa, 'y', label = 'Optimized')
      plt.legend()
      plt.show(block=False)
      return p1
  
  
  ptp = ([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14])
  pir = ([150,85,90,50,45,60,60,40,40,30,28,30,38,30,26])
  
  hypRegress(ptp,pir)
  harRegress(ptp,pir)
  
  input('pause')
  </code></pre>