- #1
member 428835
Hi PF!
I am trying to integrate functions over an infinite domain. One example is $$\int_0^\infty \frac{e^{-x}}{\sqrt{x}}\,dx$$ I know the substitution ##u = \sqrt{x}## reduces this problem to integrating ##\exp(-x^2)##, but if I want to integrate the function as is, how would I do this?
I've already tried Gauss-Legendre quadrature and Romberg integration. GL reports NaN and Romberg is evidently unable to handle the infinite limits.
I am trying to integrate functions over an infinite domain. One example is $$\int_0^\infty \frac{e^{-x}}{\sqrt{x}}\,dx$$ I know the substitution ##u = \sqrt{x}## reduces this problem to integrating ##\exp(-x^2)##, but if I want to integrate the function as is, how would I do this?
I've already tried Gauss-Legendre quadrature and Romberg integration. GL reports NaN and Romberg is evidently unable to handle the infinite limits.
Python:
import numpy as np
import scipy
import scipy.linalg# SciPy Linear Algebra Library
from matplotlib import pyplot as plt# plotting
from scipy import integrate
f = lambda x: np.exp(-x)/np.sqrt(x)# function to integrate
a = 0# lower bound
b = np.inf# upper bound
toler = 10e-3# tolerance
exact = 1.772453850# exact value of integral
# Romberg Integration
I = integrate.romberg(f, a, b, rtol=toler, show=True, divmax=25)
# Gauss-Legendre Quadrature Integration
deg = 1# degree of Legendre poly
gauss = 0# initial guess
while abs(exact-gauss) > toler:
x, w = np.polynomial.legendre.leggauss(deg)
# Translate x values from the interval [-1, 1] to [a, b]
t = 0.5*(x + 1)*(b - a) + a
gauss = sum(w * f(t)) * 0.5*(b - a)
deg = deg + 1
print gauss
print deg