python - solve an equation containing integrals -


i need solve integral equation embedded integral equation python 3.2 in win7.

there 2 integral equations.

the code here:

import numpy np scipy.optimize.minpack import fsolve numpy import exp scipy.integrate.quadpack import quad import matplotlib.pyplot plt import sympy syp  lb = 0  def integrand2(x, a):     print("integrand2 called")     return x**(a-1) * exp(-x)  def integrand1(x, b, c):     print("integrand1 called")     integral , err = quad(integrand2, lb/b, syp.oo , args=(1+c))     return c/(b*integral)  def intergralfunc1(b,c):     integral,err = quad(integrand1, 0, 10, args=(b,c))      print("integral ", integral, " , err ", err)     print("b ", b, " , c ", c)     return 10 - integral  def findguess():     vfunc = np.vectorize(intergralfunc1)     f1 = np.linspace(0.01, 10,10)     f2 = np.linspace(0.01, 10,10)     result = vfunc(f1, f2)     plt.plot(f1, result)     plt.xlabel('f1')     plt.subplot(211)      plt.plot(f2, result)     plt.xlabel('f2')     plt.subplot(212)     plt.show()  def solvefunction():     sol= fsolve(intergralfunc1, 5, 5, full_output=true)     return sol  if __name__ == '__main__':      findguess()      sol = solvefunction()     print("sol ", sol)     print("verification: \n")     print("f(b,c) ", intergralfunc1(sol[0],5)) 

i got results make no sense.

     integral  nan  , err  nan      b  [ 5.]  , c  5      f(b,c)  nan 

any appreciated !!!

for reason integrand1 returning numpy.ndarray expected return float.

also on machine numpy reported

 y:289: userwarning: extremely bad integrand behavior occurs @ points of   integration interval. 

which means problem numerically instable. therefore nonsensical results expected.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -