pdeCoeff1D
First version: 3.00.6.1
Syntax
pdeCoeff1D(diff, [conv=0], [react=0], [source=0], [mass=1])
Details
Constructs a coefficient dictionary in operator form for a one-dimensional partial differential equation (PDE).
This function wraps the equation coefficients, including diffusion, convection, reaction, source, and mass terms, into a coefficient dictionary object that can be recognized by the solver pdeSolver. It supports both constant coefficients (scalars) and variable coefficients (functions).
Parameters
diff Numeric scalar or function that specifies the diffusion coefficient.
conv (optional) Numeric scalar or function that specifies the convection coefficient. The default value is 0.
react (optional) Numeric scalar or function that specifies the reaction coefficient. The default value is 0.
source (optional) Numeric scalar or function that specifies the source term. The default value is 0.
mass (optional) Numeric scalar or function that specifies the mass coefficient. The default value is 1.
Note:
If a coefficient is a scalar, it must be a finite valid value, that is, not NULL, NaN, or Inf.
If a coefficient is a function, it must accept 2 parameters, usually representing spatial position and time, and return a finite numeric scalar. It must not return non-scalar structures, such as vectors or matrices, or non-numeric types, such as Boolean, temporal, or DECIMAL.
During the solving stage, the mass coefficient must always be positive and finite.
Returns
Returns a dictionary containing the following fields:
type: STRING scalar, fixed to "operator1D".
dim: INT scalar, fixed to 1.
form: STRING scalar, fixed to "operator".
diff: DOUBLE scalar or function, the diffusion coefficient.
conv: DOUBLE scalar or function, the convection coefficient.
react: DOUBLE scalar or function, the reaction coefficient.
source: DOUBLE scalar or function, the source coefficient.
mass: DOUBLE scalar or function, the mass coefficient.
Examples
Example 1. Construct a diffusion equation with constant coefficients
coeff = pdeCoeff1D(diff=0.2)
Example 2. Construct a complete one-dimensional convection-diffusion-reaction equation
coeff = pdeCoeff1D(diff=0.01, conv=-0.3, react=-0.05, source=2.0, mass=1.5)
Example 3. Construct variable coefficients (Black-Scholes model)
coeff = pdeCoeff1D(
diff=def(S, tau) { return 0.5 * 0.2 * 0.2 * S * S },
conv=def(S, tau) { return 0.05 * S },
react=-0.05
)
