Main Content

`specifyCoefficients`

This section describes how to write the coefficient `f`

in
the equation

$$m\frac{{\partial}^{2}u}{\partial {t}^{2}}+d\frac{\partial u}{\partial t}-\nabla \xb7\left(c\nabla u\right)+au=f$$

or in similar equations. The question is how to write the coefficient `f`

for
inclusion in the PDE model via `specifyCoefficients`

.

*N* is the number of equations, see Equations You Can Solve Using PDE Toolbox.
Give `f`

as either of the following:

If

`f`

is constant, give a column vector with*N*components. For example, if*N*= 3,`f`

could be:f = [3;4;10];

If

`f`

is not constant, give a function handle. The function must be of the formfcoeff = fcoeffunction(location,state)

Pass the coefficient to

`specifyCoefficients`

as a function handle, such asspecifyCoefficients(model,'f',@fcoeffunction,...)

`solvepde`

or`solvepdeeig`

compute and populate the data in the`location`

and`state`

structure arrays and pass this data to your function. You can define your function so that its output depends on this data. You can use any names instead of`location`

and`state`

, but the function must have exactly two arguments. To use additional arguments in your function, wrap your function (that takes additional arguments) with an anonymous function that takes only the`location`

and`state`

arguments. For example:fcoeff = ... @(location,state) myfunWithAdditionalArgs(location,state,arg1,arg2...) specifyCoefficients(model,'f',fcoeff,...

`location`

is a structure with these fields:`location.x`

`location.y`

`location.z`

`location.subdomain`

The fields

`x`

,`y`

, and`z`

represent the*x*-,*y*-, and*z*- coordinates of points for which your function calculates coefficient values. The`subdomain`

field represents the subdomain numbers, which currently apply only to 2-D models. The location fields are row vectors.`state`

is a structure with these fields:`state.u`

`state.ux`

`state.uy`

`state.uz`

`state.time`

The

`state.u`

field represents the current value of the solution*u*. The`state.ux`

,`state.uy`

, and`state.uz`

fields are estimates of the solution’s partial derivatives (∂*u*/∂*x*, ∂*u*/∂*y*, and ∂*u*/∂*z*) at the corresponding points of the location structure. The solution and gradient estimates are*N*-by-*Nr*matrices. The`state.time`

field is a scalar representing time for time-dependent models.

Your function must return a matrix of size *N*-by-*Nr*,
where *Nr* is the number of points in the location that
`solvepde`

passes. *Nr* is equal to the length of
the `location.x`

or any other `location`

field. The
function should evaluate `f`

at these points.

For example, if *N* = 3, `f`

could be:

function f = fcoeffunction(location,state) N = 3; % Number of equations nr = length(location.x); % Number of columns f = zeros(N,nr); % Allocate f % Now the particular functional form of f f(1,:) = location.x - location.y + state.u(1,:); f(2,:) = 1 + tanh(state.ux(1,:)) + tanh(state.uy(3,:)); f(3,:) = (5 + state.u(3,:)).*sqrt(location.x.^2 + location.y.^2);

This represents the coefficient function

$$f=\left[\begin{array}{c}x-y+u(1)\\ 1+\mathrm{tanh}(\partial u(1)/\partial x)+\mathrm{tanh}(\partial u(3)/\partial y)\\ (5+u(3))\sqrt{{x}^{2}+{y}^{2}}\end{array}\right]$$