pdeGrid1D
First version: 3.00.6.1
Syntax
pdeGrid1D(xMin, xMax, n, [gridType="uniform"], [focus=NULL], [density=2.0])
Details
Generates a strictly increasing DOUBLE vector with n nodes, which serves as the spatial grid nodes for solving partial differential equations (PDEs).
During numerical solving, a continuous physical space needs to be discretized into a series of coordinate points. This function supports generating uniformly distributed grids and refined, non-uniform grids around a specified location using mathematical functions such as sinh, improving numerical accuracy in key regions.
Main use cases:
Spatial discretization: divide the specified computational range into n computational nodes.
Flexible refinement strategy: refine the grid around a specific point, such as the strike price in option pricing, to balance computational efficiency and accuracy.
Parameters
xMin Numeric scalar that specifies the left endpoint of the spatial interval. It must be a finite valid value, that is, not NULL, NaN, or Inf, and must be less than xMax. When gridType is "log", xMin must be greater than 0.
xMax Numeric scalar that specifies the right endpoint of the spatial interval. It must be a finite valid value, that is, not NULL, NaN, or Inf, and must be greater than xMin.
n INT scalar that specifies the number of grid nodes. The valid range is 3 to 2,147,483,647.
gridType (optional) STRING scalar that specifies the grid type. The default value is "uniform". Supported values are case-sensitive:
"uniform": Generates a uniform grid.
"sinh": Generates a hyperbolic-sine focused grid.
"tanh": Generates a hyperbolic-tangent focused grid.
"log": Generates an exponential or logarithmic focused grid.
focus (optional) Numeric scalar or NULL that specifies the focus location of the non-uniform grid, namely the spatial position where grid nodes should be refined. The default value is NULL.
When gridType is "sinh", "tanh", or "log", focus must be provided as a finite numeric value, and it must be within xMin and xMax, inclusive. If focus is equal to xMin or xMax, a one-sided focused grid is generated. focus controls where the grid is refined, but it does not guarantee that the value appears as a node in the output vector. The output nodes contain the exact value only when its normalized position happens to correspond to a node index.
When gridType is "uniform", a uniform grid is generated and no focus location is required, so focus must be omitted or explicitly passed as NULL.
density (optional) Numeric scalar that specifies the refinement intensity at the focus location (focus). The default value is 2.0. It must be a finite valid value, that is, not NULL, NaN, or Inf. Its valid range and behavior depend on gridType:
"uniform": Must remain at the default value 2.0. If another numeric value is passed, the system reports an error instead of silently ignoring it.
"sinh": Valid range is [0, 10]. When the value is 0, the grid degenerates to a uniform distribution.
"tanh": Valid range is [0, 3]. When the value is 0, the grid degenerates to a uniform distribution.
"log": Valid range is [0, 10]. When the value is 0, the grid degenerates to a uniform distribution.
Returns
Returns a DOUBLE vector:
The vector length equals n.
The elements in the vector are strictly increasing spatial nodes.
The first element is the normalized xMin, and the last element is the normalized xMax.
Examples
Example 1. Generate a uniform grid
pdeGrid1D(0.0, 1.0, 5)
// output: 0.0 0.25 0.5 0.75 1.0
Example 2. Generate a sinh-focused grid around the strike price
spotGrid = pdeGrid1D(0.0, 300.0, 401, "sinh", 100.0, 3.0)
domain = pdeDomain1D(spotGrid)
Example 3. Generate a tanh-centered focused grid
grid = pdeGrid1D(-1.0, 1.0, 101, "tanh", 0.0, 2.0)
Example 4. Generate a log-focused grid over a positive interval
grid = pdeGrid1D(1.0, 100.0, 101, "log", 20.0, 2.0)
Example 5. Apply one-sided refinement near the left endpoint
grid = pdeGrid1D(0.0, 1.0, 101, "sinh", 0.0, 3.0)
Example 6. Degenerate to a uniform grid when density is 0
grid = pdeGrid1D(0.0, 1.0, 5, "sinh", 0.25, 0.0)
The returned result is the same as pdeGrid1D(0.0, 1.0, 5).
Related Functions: pdeDomain1D, pdeDomain2D, pdeInfo, pdeSolver
