windows 7 - get all solutions (2 unknowns) from fsolve in python 3.2 -
i need solutions (2 unknowns) fsolve in python 3.2.
but, returns 1 event though have set full_output = true in fsolve.
def integrand1(x, b, c): return (x/b)**(c-1) * exp(-x/b) def intergralfunc2(b): integral,err = quad(integrand2, 0, 100, args=(b)) return 100 - integral def solvefunction(): sol= fsolve(intergralfunc1, 5, 5, full_output=true) return sol if __name__ == '__main__': sol = solvefunction() print("sol ", sol)
i need know solution b , c, but, fsolve() returns solution b.
using fmin
(see documentation) instead of fsolve
, changing integralfunc
takes sequence containing b
, c
, returns abs(100 - integral)
both parameters.
from scipy.integrate import quad 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
, c
>>> integral, err = quad(integrand, 0, 100, args=(b, c)) >>> np.allclose(100, integral) true
edit:
if have use fsolve
, work since fsolve
expects shape output of objective function same same input, different results b
, c
if use fmin
. b, c = (4.48517289097, 4.95091626134)
fsolve
, b, c = (5.14997777422, 4.85783682022)
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
Comments
Post a Comment