I need to find the roots of a function. I am currently using scipy.optimize.fsolve
def f(z):
return ((1-2*z)*np.exp(-d/z))/(((1-z)**(2+d))*(z**(2-d)))
# d is a constant ndarray of shape(300000,)
# hence f(z) is an ndarray of shape (300000,)
def trap(func,a,b,num): #trapezoidal approach to integration
xlinear=np.linspace(a,b,num)
dx=np.diff(xlinear)
fx=func(xlinear[:,None])
f12=fx[:-1,:]+fx[1:,:]
return np.dot(dx,f12)/2.0
#also returns an array of shape (300000,)
def integral(p):
return trap(f,0,p,1000)
root= fsolve(f,0.75) # 0.75 because the answer should lie in (0.5,1)
The issue is that I was expecting fsolve to return an array in line with returns of functions f and trap. However, somehow I am only getting a array of shape (1,)