1
$\begingroup$

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,)

$\endgroup$

closed as off-topic by Kirill, nicoguaro, LKlevin, Wrzlprmft, GertVdE Nov 24 '16 at 19:47

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ While the problem you're attempting to solve is based in computational science, the question is strictly on Python programming and thus off-topic here. $\endgroup$ – Spencer Bryngelson Nov 1 '16 at 4:15