Hi Guys,
i have a function called fitting. I need it for some simulations. I don't want to write down the whole code because it is to long. The part i give you interpolates two arrays to calculate zero points. The in
def find_nearest(array, value) it comes to the error in the subject. i call the function with x = fitting(c_cecora). When i run only the algorithm without define it es def fitting(c_cecora) it runs...but when i call it with x = fitting(c_cecora) it fails. Can you please help me?
Code:
def fitting(c_cecora)... data = np.genfromtxt(vers,delimiter=' ')
C_f = data[:,][:,1]
xH = data[:,][:,0]
x1 = np.linspace(0.0, 50.0, num=430)
y1 = np.linspace(0.0, 0.0, num=430)
xH = np.array(xH)
C_f = np.array(C_f)
x1 = np.array(x1)
y1 = np.array(y1)
p1=interpolate.PiecewisePolynomial(xH,C_f[:,np.newaxis])
p2=interpolate.PiecewisePolynomial(x1,y1[:,np.newaxis])
def pdiff(x):
return p1(x)-p2(x)
xs=np.r_[xH,x1]
xs.sort()
x_min=xs.min()
x_max=xs.max()
x_mid=xs[:-1]+np.diff(xs)/2
roots=set()
for val in x_mid:
root,infodict,ier,mesg = optimize.fsolve(pdiff,val,full_output=True)
# ier==1 indicates a root has been found
if ier==1 and x_min<root<x_max:
roots.add(root[0])
roots=list(roots)
#print(np.column_stack((roots,p1(roots),p2(roots))))
def find_nearest(array,value):
idx = (np.abs(array-value)).argmin()
return array[idx]
array = np.array(roots)
value = 6.23