human
I am working on the file "Syllabus_in_notebooks/Sec6_5_1_Hantush-well-1.ipynb".
The first task is:
Implementing the integral
Can you write Python program for it?
assistant
#Here is the Python program you requested.

def Wh(u, rho):
    '''Numerical integration using quad'''
    def kernel(y, rho): return np.exp(-y - (rho / 2)**2 /y)  / y
    def wh(u, rho):     return quad(kernel, u, np.inf, (rho,))
    wh = np.frompyfunc(wh, 2, 2)
    return wh(u, rho)[0]

def Wh2(u, rho, tol=1e-14):
    '''Return Hantush using summation.
    
    This implementation works but has a limited reach; for very small
    values of u (u<0.001) the solution will deteriorate into nonsense,
    '''
    #import pdb
    #pdb.set_trace()
    tau = (rho/2)**2 / u
    f0 = 1
    E =  exp1(u)
    w0= f0 * E
    W = w0
    for n in range(1, 500):
        E = (1/n) * (np.exp(-u) - u * E)
        f0 = -f0 / n * tau
        w1 = f0 * E
        #print(w1)
        if np.max(abs(w0 + w1)) < tol: # use w0 + w1 because terms alternate sign
            #print('succes')
            break
        W += w1
        w0 = w1 # remember previous value
    return W

# Timing and test
u = np.array([1e-3, 1e-2, 1e-1, 1, 10])
rho=0.3
print("Hantush quad :")
%timeit Wh(u, rho)
print(Wh(u, rho))
print("Hantush series:")
%timeit Wh2(u, rho)
print(Wh2(u, rho))