pdeCoeff2D

First version: 3.00.6.1

Syntax

pdeCoeff2D(xx, yy, [xy=0], [x=0], [y=0], [u=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 two-dimensional PDE.

It defines the coefficients to be solved (second-order derivatives, first-order derivatives, zero-order term, source, and mass). The returned result can be directly passed to the coeff parameter of pdeSolver for 2D problems. It supports both constant coefficients (scalars) and variable coefficients (functions). The standard equation form is as follows:

M ( x , y , t ) ∂ u ∂ t = A ( x , y , t ) ∂ 2 u ∂ x 2 + B ( x , y , t ) ∂ 2 u ∂ y 2 + C ( x , y , t ) ∂ 2 u ∂ x ∂ y + D ( x , y , t ) ∂ u ∂ x + E ( x , y , t ) ∂ u ∂ y + F ( x , y , t ) u + G ( x , y , t ) M(x,y,t)\frac{\partial u}{\partial t}=A(x,y,t)\frac{\partial^2u}{\partial x^2}+B(x,y,t)\frac{\partial^2u}{\partial y^2}+C(x,y,t)\frac{\partial^2u}{\partial x\partial y}+D(x,y,t)\frac{\partial u}{\partial x}+E(x,y,t)\frac{\partial u}{\partial y}+F(x,y,t)u+G(x,y,t)
Term Field in coeff Description

M

mass

Coefficient of the time derivative.

A

xx

Coefficient of the second-order derivative in x.

B

yy

Coefficient of the second-order derivative in y.

C

xy

Coefficient of the mixed second-order derivative.

D

x

Coefficient of the first-order derivative in x.

E

y

Coefficient of the first-order derivative in y.

F

u

Coefficient of the reaction term.

G

source

Source term.

Parameters

xx Numeric scalar or function that specifies the coefficient of the second-order derivative term in the x direction.

yy Numeric scalar or function that specifies the coefficient of the second-order derivative term in the y direction.

xy (optional) Numeric scalar or function that specifies the coefficient of the mixed derivative term. The default value is 0.

x (optional) Numeric scalar or function that specifies the coefficient of the first-order derivative term in the x direction. The default value is 0.

y (optional) Numeric scalar or function that specifies the coefficient of the first-order derivative term in the y direction. The default value is 0.

u (optional) Numeric scalar or function that specifies the coefficient of the zero-order term. The default value is 0.

source (optional) Numeric scalar or function that specifies the source term coefficient. 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, the function must accept 3 parameters, usually representing spatial positions x and y and time t.

  • 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 "operator2D".

  • dim: INT scalar, fixed to 2.

  • form: STRING scalar, fixed to "operator".

  • mass: DOUBLE scalar or function, the normalized mass value, default value, or original function object.

  • xx: DOUBLE scalar or function, the normalized xx value or original function object.

  • yy: DOUBLE scalar or function, the normalized yy value or original function object.

  • xy: DOUBLE scalar or function, the normalized xy value, default value, or original function object.

  • x: DOUBLE scalar or function, the normalized x value, default value, or original function object.

  • y: DOUBLE scalar or function, the normalized y value, default value, or original function object.

  • u: DOUBLE scalar or function, the normalized u value, default value, or original function object.

  • source: DOUBLE scalar or function, the normalized source value, default value, or original function object.

Note: Diagnostic information such as coefficient names, coefficient input types, mixed terms, and dependencies can be queried by using pdeInfo(coeff).

Examples

Example 1. Construct the coefficient dictionary corresponding to the following 2D pure diffusion equation:

∂ u ∂ t = 0.01 ∂² u ∂ x² + 0.02 ∂² u ∂ y²

coeff = pdeCoeff2D(xx=0.01, yy=0.02)

Example 2. Construct the coefficient dictionary corresponding to the following 2D convection-diffusion equation with constant diffusion, convection, and source terms:

∂ u ∂ t = 0.01 ∂ 2 u ∂ x 2 + 0.01 ∂ 2 u ∂ y 2 − 0.3 ∂ u ∂ x + 0.1 ∂ u ∂ y + 2.5

coeff = pdeCoeff2D(
    xx=0.01,
    yy=0.01,
    x=-0.3,
    y=0.1,
    source=2.5
)

Example 3. Construct the coefficient dictionary corresponding to the following equation with a mixed second-order derivative term ∂² u ∂ x ∂ y :

∂ u ∂ t = 0.1 ∂² u ∂ x² + 0.2 ∂² u ∂ y² − 0.05 ∂² u ∂ x ∂ y

coeff = pdeCoeff2D(
    xx=0.1,
    yy=0.2,
    xy=-0.05
)

Example 4. Construct the coefficient dictionary for European option pricing under the Heston stochastic volatility model (where S is the asset price, v is the variance, and tau is time to maturity):

∂ u ∂ τ = 1 2 v S 2 ∂² u ∂ S² + 0.045 v ∂² u ∂ v² − 0.21 v S ∂² u ∂ S ∂ v + 0.05 S ∂ u ∂ S + 2.0 ( 0.04 − v ) ∂ u ∂ v − 0.05 u

coeff = pdeCoeff2D(
    xx=def(S, v, tau) {
        return 0.5 * v * S * S
    },
    yy=def(S, v, tau) {
        return 0.5 * 0.3 * 0.3 * v
    },
    xy=def(S, v, tau) {
        return -0.7 * 0.3 * v * S
    },
    x=def(S, v, tau) {
        return 0.05 * S
    },
    y=def(S, v, tau) {
        return 2.0 * (0.04 - v)
    },
    u=-0.05
)

Example 5. Specify custom functions for the mass term (mass) and source term (source), corresponding to the equation:

1.0 · ∂ u ∂ t = 1.0 ( i.e. , ∂ u ∂ t = 1 )

coeff = pdeCoeff2D(
    xx=def(x, y, t) { return 0.0 },
    yy=def(x, y, t) { return 0.0 },
    source=def(x, y, t) { return 1.0 },
    mass=def(x, y, t) { return 1.0 }
)

Related Functions: pdeInfo, pdeSolver