f Coefficient for specifyCoefficients
This section describes how to write the coefficient f
in
the equation
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 Partial Differential Equation 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
can 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
orsolvepdeeig
compute and populate the data in thelocation
andstate
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 oflocation
andstate
, 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 thelocation
andstate
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
, andz
represent the x-, y-, and z- coordinates of points for which your function calculates coefficient values. Thesubdomain
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. Thestate.ux
,state.uy
, andstate.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. Thestate.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