Gauss-Hermite quadrature. Computes the sample points and weights for Gauss-Hermite quadrature. These sample points and weights will correctly integrate polynomials of degree :math:`2*deg - 1` or less over the interval :math:`[-\\inf, \\inf]` with the weight function :math:`f(x)
(deg)
| 1557 | |
| 1558 | |
| 1559 | def hermgauss(deg): |
| 1560 | """ |
| 1561 | Gauss-Hermite quadrature. |
| 1562 | |
| 1563 | Computes the sample points and weights for Gauss-Hermite quadrature. |
| 1564 | These sample points and weights will correctly integrate polynomials of |
| 1565 | degree :math:`2*deg - 1` or less over the interval :math:`[-\\inf, \\inf]` |
| 1566 | with the weight function :math:`f(x) = \\exp(-x^2)`. |
| 1567 | |
| 1568 | Parameters |
| 1569 | ---------- |
| 1570 | deg : int |
| 1571 | Number of sample points and weights. It must be >= 1. |
| 1572 | |
| 1573 | Returns |
| 1574 | ------- |
| 1575 | x : ndarray |
| 1576 | 1-D ndarray containing the sample points. |
| 1577 | y : ndarray |
| 1578 | 1-D ndarray containing the weights. |
| 1579 | |
| 1580 | Notes |
| 1581 | ----- |
| 1582 | |
| 1583 | .. versionadded:: 1.7.0 |
| 1584 | |
| 1585 | The results have only been tested up to degree 100, higher degrees may |
| 1586 | be problematic. The weights are determined by using the fact that |
| 1587 | |
| 1588 | .. math:: w_k = c / (H'_n(x_k) * H_{n-1}(x_k)) |
| 1589 | |
| 1590 | where :math:`c` is a constant independent of :math:`k` and :math:`x_k` |
| 1591 | is the k'th root of :math:`H_n`, and then scaling the results to get |
| 1592 | the right value when integrating 1. |
| 1593 | |
| 1594 | """ |
| 1595 | ideg = pu._deprecate_as_int(deg, "deg") |
| 1596 | if ideg <= 0: |
| 1597 | raise ValueError("deg must be a positive integer") |
| 1598 | |
| 1599 | # first approximation of roots. We use the fact that the companion |
| 1600 | # matrix is symmetric in this case in order to obtain better zeros. |
| 1601 | c = np.array([0]*deg + [1], dtype=np.float64) |
| 1602 | m = hermcompanion(c) |
| 1603 | x = la.eigvalsh(m) |
| 1604 | |
| 1605 | # improve roots by one application of Newton |
| 1606 | dy = _normed_hermite_n(x, ideg) |
| 1607 | df = _normed_hermite_n(x, ideg - 1) * np.sqrt(2*ideg) |
| 1608 | x -= dy/df |
| 1609 | |
| 1610 | # compute the weights. We scale the factor to avoid possible numerical |
| 1611 | # overflow. |
| 1612 | fm = _normed_hermite_n(x, ideg - 1) |
| 1613 | fm /= np.abs(fm).max() |
| 1614 | w = 1/(fm * fm) |
| 1615 | |
| 1616 | # for Hermite we can also symmetrize |
nothing calls this directly
no test coverage detected