The gamma function is defined by Write a program to compute the value of this function from the…
The gamma function is defined by
Write a program to compute the value of this function from the definition using each of the following approaches:
(a) Truncate the infinite interval of integration and use a composite quadrature rule, such as trapezoid or Simpson. You will need to do some experimentation or analysis to determine where to truncate the interval, based on the usual tradeoff between efficiency and accuracy.
(b) Truncate the interval and use a standard adaptive quadrature routine. Again, explore the tradeoff between accuracy and efficiency.
(c) Gauss-Laguerre quadrature is designed for the interval [0, ∞] and the weight function e −t , so it is ideal for approximating this integral. Look up the nodes and weights for Gauss-Laguerre quadrature rules of various orders (see [2, 447, 521], for example) and compute the resulting estimates for the integral.
(d) If available, use an adaptive quadrature routine designed for an unbounded interval of integration.
For each method, compute the approximate value of the integral for several values of x in the range 1 to 10. Compare your results with the values given by the built-in gamma function or with the known values for integer arguments,
How do the various methods compare in efficiency for a given level of accuracy?