solve an integral equation by python
numpy, python, python-3.x, scipy
Solution
Just made the following change and it should work (it worked for me).
remove:
from cmath import exp, cos
include:
from numpy import exp, cos
as explained in the comments, the `cmath` functions accept only `float` inputs, not arrays.
Problem
I need to solve an integral equation by python 3.2 in win7. I want to find an initial guess solution first and then use "fsolve()" to solve it in python. This is the code: ``` import numpy as np from scipy.optimize.minpack import fsolve from cmath import cos, exp from scipy.integrate.quadpack import quad def integrand2(x, b): return exp(-x)/b def intergralFunc2(b): integral,err = quad(integrand2, 0, 10, args=(b)) // **error here** return 0.01 - integral import matplotlib.pyplot as plt def findGuess(): vfunc = np.vectorize(intergralFunc2) f = np.linspace(-20, 20,10) plt.plot(f, vfunc(f)) plt.xlabel('guess value') plt.show() def solveFunction(): y= fsolve(intergralFunc2, 10) return y if __name__ == '__main__': findGuess() solution = solveFunction() print("solution is ", solution) ``` I got error: ``` quadpack.error: Supplied function does not return a valid float. ``` Any help would be appreciated.