To get the hang of Gauss-Laguerre integration I have decided to calculate the following integral numerically, which can be compared to the known analytical solution:
\begin{align} \int_0^{\infty} s^3 \exp(-s^2 t) \, \mathrm{d}t = s \end{align}
The result can be seen in the graph below. The result matches the analytical solution only on a limited subrange of the independent variable $s$. Evidently more care is needed to ensure convergence of the numerical solution for all $s$. Perhaps the integration routine must be used on smaller subranges? My question is, how can I make Gauss-Laguerre (or Gaussian Quadrature in general) applicable to problems of the kind shown above, where I need the solution to be accurate for all $s$?
import numpy as np
import matplotlib.pyplot as plt
def integrand(t, s):
return s ** 3 * np.exp(-(s ** 2) * t) * np.exp(t)
vintegrand = np.vectorize(integrand)
def integral(omega):
I = np.dot(vintegrand(ti, omega), wi)
return I
vintegral = np.vectorize(integral)
ti, wi, = np.polynomial.laguerre.laggauss(175)
s = np.linspace(-50, 50, 100)
Is = vintegral(s)
plt.plot(s, Is, "b", label="$I(s)$ numerical solution")
plt.plot(s, s, "r", label="$I(s) = s$ analytical solution")
plt.xlabel("$s$")
plt.legend()
plt.show()