title: Why does function containing "scipy.integration" produces some wrong results together with correct?
body: <p>I wrote a function for <a href="https://i.stack.imgur.com/M0I7V.jpg" rel="nofollow noreferrer">these equations </a></p>
  
  <blockquote>
    <p>f(r) = 1/r(-1/2*((ln(r/rp)/sp)^2)</p>
    
    <p>Y=integral1(f(r)*(1-x/r)^2)/integral2(f(r))</p>
    
    <p>with integral 1 from x to infinity and integral 2 from 0 to infinity</p>
  </blockquote>
  
  <p>Later I want to fit according to the function but currently I am only using it to create Y for selected x Data. </p>
  
  <p>However, when plotting using certain values for the variables rp and sp (rp: 20.74, sp: 0.053)) the values for Y are completely off from the actual curve for low x values: the values of Y drop to almost 0 for x smaller than approx 0.6.</p>
  
  <p>When changing the variables, e.g. to rp: 20.74 and sp: 0.53 it works.</p>
  
  <p>Graph of the curve with outlier can be found <a href="https://i.stack.imgur.com/Jqzrd.jpg" rel="nofollow noreferrer">here</a> and the graph of the curve without any outlier (rp: 20.74 and sp: 0.53) can be found <a href="https://i.stack.imgur.com/eSa6n.jpg" rel="nofollow noreferrer">here</a></p>
  
  <p>I assume it has to do with my code respectively the way I am using the integrals, but I can't find out what is the mistake.</p>
  
  <pre><code>import numpy as np
  import scipy.integrate
  import scipy.optimize
  import matplotlib.pyplot as plt
  
  def func(x,rp,sp):
      #Funktion für Kurvenfit
      fn_up = lambda r,rdex : (1/r*np.exp(-1/2*((np.log(r/rp))/sp)**2))*((1-(rdex/r))**2)
      fn_low = lambda r : (1/r*np.exp(-1/2*((np.log(r/rp))/sp)**2))
      num_up = np.asarray([scipy.integrate.quad(fn_up, _x, np.inf,args=(_x,))[0] for _x in x])
      num_low = np.asarray([scipy.integrate.quad(fn_low, 0, np.inf)[0]])
      Kd=num_up/num_low
      return Kd
  
  rp=20.74
  sp=0.053
  R = np.arange(0.,40.,0.25)
  Kd = func(R,rp,sp)
  </code></pre>