f Coefficient for
This section describes how to write the coefficient
or in similar equations. The question is how to write the coefficient
inclusion in the PDE model via
N is the number of equations, see Equations You Can Solve Using PDE Toolbox.
f as either of the following:
fis constant, give a column vector with N components. For example, if N = 3,
f = [3;4;10];
fis not constant, give a function handle. The function must be of the form
fcoeff = fcoeffunction(location,state)
Pass the coefficient to
specifyCoefficientsas a function handle, such as
solvepdeeigcompute and populate the data in the
statestructure 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
statearguments. For example:
fcoeff = ... @(location,state) myfunWithAdditionalArgs(location,state,arg1,arg2...) specifyCoefficients(model,'f',fcoeff,...
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 N-by-Nr,
where Nr is the number of points in the location that
solvepde passes. Nr is equal to the length of
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