Using fmin
(see the documentation) instead of fsolve
and changing integralFunc
so that it takes a sequence containing b
and c
and returns abs(100 - integral)
will get both parameters.
from scipy.integrate import quad
from scipy.optimize import fmin
def integrand(x, b, c):
return (x/b)**(c-1) * exp(-x/b)
def intergralFunc(bc):
integral,err = quad(integrand, 0, 100, args=(bc[0], bc[1]))
return abs(100 - integral)
def solveFunction():
sol= fmin(intergralFunc, [5, 5])
return sol
b, c = solveFunction()
Output:
Optimization terminated successfully.
Current function value: 0.000000
Iterations: 49
Function evaluations: 89
Checking b
and c
>>> integral, err = quad(integrand, 0, 100, args=(b, c))
>>> np.allclose(100, integral)
True
EDIT:
If you have to use fsolve
, this will work since fsolve
expects the shape output of the objective function to be the same same as the input, but you will get slightly different results for b
and c
than if you use fmin
. I get b, c = (4.48517289097, 4.95091626134)
with fsolve
and b, c = (5.14997777422, 4.85783682022)
with fmin
def intergralFunc(bc):
integral,err = quad(integrand, 0, 100, args=(bc[0], bc[1]))
return np.array([100 - integral] * 2)
def solveFunction():
sol= fsolve(intergralFunc, [5, 5])
return sol