Learn R Programming

capn (version 2.0.0)

unigrids: Generate Uniform Grids

Description

Generate a multi-dimensional uniform grid over bounded intervals.

Usage

unigrids(nnodes, lb, ub, rtype = NULL)

Value

A list with \(d\) elements of uniform nodes, or a \( \left( \displaystyle \prod_{i=1}^{d} n_{i} \right) \times d\)

matrix of uniform grid points.

Arguments

nnodes

A vector specifying the number of nodes in each dimension.

lb

A vector of lower bounds for each dimension.

ub

A vector of upper bounds for each dimension.

rtype

Type of return value. The default NULL returns a list. If rtype = "list", a list is returned. If rtype = "grid", a matrix is returned.

Details

For the \(i\)-th dimension, \(i = 1, 2, \ldots, d\), suppose a polynomial approximant \(s_{i}\) over a bounded interval \([a_{i}, b_{i}]\) is defined by evenly spaced nodes. Then, a \(d\)-dimensional uniform grid is defined as:

\(\mathbf{S} = \left\{ (s_{1}, s_{2}, \ldots, s_{d}) \mid a_{i} \leq s_{i} \leq b_{i}, \; i = 1, 2, \ldots, d \right\}. \)

This corresponds to all combinations of the marginal grids \(s_{i}\). Two types of return values are provided. rtype = "list" returns a list of length \(d\) containing the marginal grids, whereas rtype = "grid" returns a \( \left( \displaystyle \prod_{i=1}^{d} n_{i} \right) \times d\) matrix of all grid points.

Examples

Run this code
## Uniform grid with two dimensions
unigrids(c(5, 3), c(1, 1), c(2, 3))

## Returns the same result explicitly as a list
unigrids(c(5, 3), c(1, 1), c(2, 3), rtype = "list")

## Returns a matrix of grid points over the same domain
unigrids(c(5, 3), c(1, 1), c(2, 3), rtype = "grid")

## Uniform grid with one dimension
unigrids(5, 1, 2)

## Uniform grid with three dimensions
unigrids(c(3, 4, 5), c(1, 1, 1), c(2, 3, 4), rtype = "grid")

Run the code above in your browser using DataLab