def interval_design(a, b, N): """ Equally spaced points on an interval. :param float a: The left endpoint of the interval. :param flaot b: The right endpoint of the interval. :param int N: int The number of points in the design. :return: design, N-by-1 matrix that contains the design points in the interval. It does not contain the endpoints. :rtype: ndarray """ logging.getLogger(__name__).debug('Interval design with {:d} points.'.format(N)) y = np.linspace(a, b, N+2) design = mi.atleast_2d_col(y[1:-1]) return design
def gauss_hermite(N): """ Tensor product Gauss-Hermite quadrature rule. :param int[] N: Number of nodes in each dimension of the quadrature rule :return: x, N-by-1 array of quadrature nodes :rtype: ndarray :return: w, N-by-1 array of quadrature weights :rtype: ndarray **Notes** This computation is inspired by Walter Gautschi's code at https://www.cs.purdue.edu/archives/2002/wxg/codes/OPQ.html. """ if isinstance(N, int): N = [N] if type(N) is not list: raise TypeError("N must be a list.") Npts = int(np.prod(np.array(N))) logging.getLogger(__name__).debug( "Making a tensor product Gauss-Hermite rule with {:d} points in {:d} dimensions.".format(Npts, len(N)) ) if len(N) == 1: x, w = gh1d(N[0]) else: x = np.array([[1.0]]) w = np.array([[1.0]]) for n in N: xi, wi = gh1d(n) xL = np.kron(x.copy(), np.ones(xi.shape)) xU = np.kron(np.ones((x.shape[0], 1)), xi) x = np.hstack((xL, xU)) w = np.kron(w.copy(), wi) x, w = np.atleast_2d(x[:, 1:]), mi.atleast_2d_col(w) return x, w
def gauss_legendre(N): """Tensor product Gauss-Legendre quadrature rule. Parameters ---------- N : int[] number of nodes in each dimension of the quadrature rule Returns ------- x : ndarray N-by-1 array of quadrature nodes w : ndarray N-by-1 array of quadrature weights Notes ----- This computation is inspired by Walter Gautschi's code at https://www.cs.purdue.edu/archives/2002/wxg/codes/OPQ.html. """ if isinstance(N, Integral): N = [N] if type(N) is not list: raise TypeError('N must be a list.') if len(N) == 1: x, w = gl1d(N[0]) else: x = np.array([[1.0]]) w = np.array([[1.0]]) for n in N: xi, wi = gl1d(n) xL = np.kron(x.copy(), np.ones(xi.shape)) xU = np.kron(np.ones((x.shape[0],1)), xi) x = np.hstack((xL, xU)) w = np.kron(w.copy(), wi) x, w = np.atleast_2d(x[:,1:]), mi.atleast_2d_col(w) return x, w
def gauss_legendre(N): """Tensor product Gauss-Legendre quadrature rule. Parameters ---------- N : int[] number of nodes in each dimension of the quadrature rule Returns ------- x : ndarray N-by-1 array of quadrature nodes w : ndarray N-by-1 array of quadrature weights Notes ----- This computation is inspired by Walter Gautschi's code at https://www.cs.purdue.edu/archives/2002/wxg/codes/OPQ.html. """ if isinstance(N, int): N = [N] if type(N) is not list: raise TypeError('N must be a list.') if len(N) == 1: x, w = gl1d(N[0]) else: x = np.array([[1.0]]) w = np.array([[1.0]]) for n in N: xi, wi = gl1d(n) xL = np.kron(x.copy(), np.ones(xi.shape)) xU = np.kron(np.ones((x.shape[0],1)), xi) x = np.hstack((xL, xU)) w = np.kron(w.copy(), wi) x, w = np.atleast_2d(x[:,1:]), mi.atleast_2d_col(w) return x, w
def interval_design(a, b, N): """Equally spaced points on an interval. Parameters ---------- a : float the left endpoint of the interval b : float the right endpoint of the interval N : int the number of points in the design Returns ------- design, ndarray N-by-1 matrix that contains the design points in the interval. It does not contain the endpoints. """ y = np.linspace(a, b, N+2) design = mi.atleast_2d_col(y[1:-1]) return design