m, d, or a Coefficient for
Coefficients m, d, or a
This section describes how to write the m, d, or a coefficients in the system of equations
or in the eigenvalue system
The topic applies to the recommended workflow for including
coefficients in your model using
If there are N equations in the system, then these coefficients represent N-by-N matrices.
For constant (numeric) coefficient matrices, represent each
coefficient using a column vector with N2 components.
This column vector represents, for example,
For nonconstant coefficient matrices, see Nonconstant m, d, or a.
d coefficient takes a special matrix
m is nonzero. See d Coefficient When m Is Nonzero.
Short m, d, or a vectors
Sometimes, your m, d, or a matrices are diagonal or symmetric. In these cases, you can represent m, d, or a using a smaller vector than one with N2 components. The following sections give the possibilities.
Scalar m, d, or a
The software interprets a scalar m, d, or a as a diagonal matrix.
N-Element Column Vector m, d, or a
The software interprets an N-element column vector m, d, or a as a diagonal matrix.
N(N+1)/2-Element Column Vector m, d, or a
The software interprets an N(N+1)/2-element column vector m, d, or a as a symmetric matrix. In the following diagram, • means the entry is symmetric.
is in row (j(j–1)/2+i)
of the vector
N2-Element Column Vector m, d, or a
The software interprets an N2-element column vector m, d, or a as a matrix.
is in row (N(j–1)+i)
of the vector
Nonconstant m, d, or a
If both m and d are nonzero, then d must be a constant scalar or vector, not a function.
If any of the m, d, or a coefficients is not constant, represent it as a function of the form
dcoeff = dcoeffunction(location,state)
Pass the coefficient to
specifyCoefficients as a function handle,
solvepdeeig compute and populate
the data in the
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
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
state arguments. For
dcoeff = ... @(location,state) myfunWithAdditionalArgs(location,state,arg1,arg2...) specifyCoefficients(model,"d",dcoeff,...
locationis a structure with these fields:
zrepresent the x-, y-, and z- coordinates of points for which your function calculates coefficient values. The
subdomainfield represents the subdomain numbers, which currently apply only to 2-D models. The location fields are row vectors.
stateis a structure with these fields:
state.ufield represents the current value of the solution u. The
state.uzfields 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.timefield is a scalar representing time for time-dependent models.
Your function must return a matrix of size N1-by-Nr, where:
N1 is the length of the vector representing the coefficient. There are several possible values of N1, detailed in Short m, d, or a vectors. 1 ≤ N1 ≤ N2.
Nr is the number of points in the location that the solver passes. Nr is equal to the length of the
location.xor any other
locationfield. The function should evaluate m, d, or a at these points.
For example, suppose N =
3, and you have 2-D geometry. Suppose your
is of the form
where s1(x,y) is 5 in subdomain 1, and is 10 in subdomain 2.
d is a symmetric matrix. So it is natural
d as a N(N+1)/2-Element Column Vector m, d, or a:
For that form, the following function is appropriate.
function dmatrix = dcoeffunction(location,state) n1 = 6; nr = numel(location.x); dmatrix = zeros(n1,nr); dmatrix(1,:) = ones(1,nr); dmatrix(2,:) = 5*location.subdomain; dmatrix(3,:) = 4*ones(1,nr); dmatrix(4,:) = sqrt(location.x.^2 + location.y.^2); dmatrix(5,:) = -ones(1,nr); dmatrix(6,:) = 9*ones(1,nr);
To include this function as your
pass the function handle