specifyCoefficients
This section describes how to write the coefficientf
in the equation
or in similar equations. The question is how to write the coefficientf
for inclusion in the PDE model viaspecifyCoefficients
.
Nis the number of equations, see方程可以解决强g PDE Toolbox. Givef
as either of the following:
Iff
is constant, give a column vector withNcomponents. For example, ifN= 3,f
could be:
f = [3;4;10];
Iff
is not constant, give a function handle. The function must be of the form
fcoeff = fcoeffunction(location,state)
Pass the coefficient tospecifyCoefficients
as a function handle, such as
specifyCoefficients(model,'f',@fcoeffunction,...)
solvepde
orsolvepdeeig
compute and populate the data in thelocation
和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 oflocation
和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 thelocation
和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 fieldsx
,y
, andz
represent thex-,y-, andz- 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
Thestate.u
field represents the current value of the solutionu. 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 areN-by-Nrmatrices. Thestate.time
field is a scalar representing time for time-dependent models.
Your function must return a matrix of sizeN-by-Nr, whereNris the number of points in the location thatsolvepde
passes.Nris equal to the length of thelocation.x
or any otherlocation
field. The function should evaluatef
at these points.
For example, ifN= 3,f
could be:
functionf = fcoeffunction(location,state) N = 3;% Number of equationsnr = length(location.x);% Number of columnsf = zeros(N,nr);% Allocate f% Now the particular functional form of ff(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