Gauss-Laguerre quadrature. Computes the sample points and weights for Gauss-Laguerre quadrature. These sample points and weights will correctly integrate polynomials of degree :math:`2*deg - 1` or less over the interval :math:`[0, \\inf]` with the weight function :math:`f(x) =
(deg)
| 1510 | |
| 1511 | |
| 1512 | def laggauss(deg): |
| 1513 | """ |
| 1514 | Gauss-Laguerre quadrature. |
| 1515 | |
| 1516 | Computes the sample points and weights for Gauss-Laguerre quadrature. |
| 1517 | These sample points and weights will correctly integrate polynomials of |
| 1518 | degree :math:`2*deg - 1` or less over the interval :math:`[0, \\inf]` |
| 1519 | with the weight function :math:`f(x) = \\exp(-x)`. |
| 1520 | |
| 1521 | Parameters |
| 1522 | ---------- |
| 1523 | deg : int |
| 1524 | Number of sample points and weights. It must be >= 1. |
| 1525 | |
| 1526 | Returns |
| 1527 | ------- |
| 1528 | x : ndarray |
| 1529 | 1-D ndarray containing the sample points. |
| 1530 | y : ndarray |
| 1531 | 1-D ndarray containing the weights. |
| 1532 | |
| 1533 | Notes |
| 1534 | ----- |
| 1535 | |
| 1536 | .. versionadded:: 1.7.0 |
| 1537 | |
| 1538 | The results have only been tested up to degree 100 higher degrees may |
| 1539 | be problematic. The weights are determined by using the fact that |
| 1540 | |
| 1541 | .. math:: w_k = c / (L'_n(x_k) * L_{n-1}(x_k)) |
| 1542 | |
| 1543 | where :math:`c` is a constant independent of :math:`k` and :math:`x_k` |
| 1544 | is the k'th root of :math:`L_n`, and then scaling the results to get |
| 1545 | the right value when integrating 1. |
| 1546 | |
| 1547 | """ |
| 1548 | ideg = pu._deprecate_as_int(deg, "deg") |
| 1549 | if ideg <= 0: |
| 1550 | raise ValueError("deg must be a positive integer") |
| 1551 | |
| 1552 | # first approximation of roots. We use the fact that the companion |
| 1553 | # matrix is symmetric in this case in order to obtain better zeros. |
| 1554 | c = np.array([0]*deg + [1]) |
| 1555 | m = lagcompanion(c) |
| 1556 | x = la.eigvalsh(m) |
| 1557 | |
| 1558 | # improve roots by one application of Newton |
| 1559 | dy = lagval(x, c) |
| 1560 | df = lagval(x, lagder(c)) |
| 1561 | x -= dy/df |
| 1562 | |
| 1563 | # compute the weights. We scale the factor to avoid possible numerical |
| 1564 | # overflow. |
| 1565 | fm = lagval(x, c[1:]) |
| 1566 | fm /= np.abs(fm).max() |
| 1567 | df /= np.abs(df).max() |
| 1568 | w = 1/(fm * df) |
| 1569 |
nothing calls this directly
no test coverage detected