I wrote a function for these equations
f(r) = 1/r(-1/2*((ln(r/rp)/sp)^2)
Y=integral1(f(r)*(1-x/r)^2)/integral2(f(r))
with integral 1 from x to infinity and integral 2 from 0 to infinity
Later I want to fit according to the function but currently I am only using it to create Y for selected x Data.
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.
When changing the variables, e.g. to rp: 20.74 and sp: 0.53 it works.
Graph of the curve with outlier can be found here and the graph of the curve without any outlier (rp: 20.74 and sp: 0.53) can be found here
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.
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)