pdeCoeff1D
First version: 3.00.6.1
Syntax
pdeCoeff1D(diff, [conv=0], [react=0], [source=0], [mass=1])
Details
A helper function for the partial differential equation (PDE) solver
pdeSolver, used to construct a coefficient dictionary in
operator form for a one-dimensional PDE.
It defines the coefficients to be solved (diffusion, convection, reaction, source, and mass), supporting both constant coefficients (scalars) and variable coefficients (functions). The standard equation form is as follows:
| Term | Field in coeff | Description |
|---|---|---|
|
M |
mass |
Coefficient of the time derivative. |
|
A |
diff |
Coefficient of the second-order diffusion term. |
|
B |
conv |
Coefficient of the first-order convection term. |
|
C |
react |
Coefficient of the reaction term. |
|
D |
source |
Source term. |
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 the coefficient dictionary corresponding to the following 1D pure diffusion equation:
coeff = pdeCoeff1D(diff=0.2)
Example 2. Construct the coefficient dictionary corresponding to the following complete equation with mass, diffusion, convection, reaction, and source terms:
coeff = pdeCoeff1D(diff=0.01, conv=-0.3, react=-0.05, source=2.0, mass=1.5)
Example 3. Construct the PDE coefficient dictionary for European option pricing under the Black-Scholes model (where S is the asset price, tau is time to maturity, volatility sigma = 0.2, and risk-free interest rate r = 0.05):
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
)
