Main Content

f Coefficient forspecifyCoefficients

This section describes how to write the coefficientfin the equation

m 2 u t 2 + d u t · ( c u ) + a u = f

or in similar equations. The question is how to write the coefficientffor inclusion in the PDE model viaspecifyCoefficients.

Nis the number of equations, see方程可以解决强g PDE Toolbox. Givefas either of the following:

  • Iffis constant, give a column vector withNcomponents. For example, ifN= 3,fcould be:

    f = [3;4;10];
  • Iffis not constant, give a function handle. The function must be of the form

    fcoeff = fcoeffunction(location,state)

    Pass the coefficient tospecifyCoefficientsas a function handle, such as

    specifyCoefficients(model,'f',@fcoeffunction,...)

    solvepdeorsolvepdeeigcompute and populate the data in thelocationstatestructure 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 oflocationstate, 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 thelocationstatearguments. For example:

    fcoeff =...@(location,state) myfunWithAdditionalArgs(location,state,arg1,arg2...)specifyCoefficients(model,'f',fcoeff,...
    • locationis a structure with these fields:

      • location.x

      • location.y

      • location.z

      • location.subdomain

      The fieldsx,y, andzrepresent thex-,y-, andz- coordinates of points for which your function calculates coefficient values. Thesubdomainfield 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.u

      • state.ux

      • state.uy

      • state.uz

      • state.time

      Thestate.ufield represents the current value of the solutionu. Thestate.ux,state.uy, andstate.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 areN-by-Nrmatrices. Thestate.timefield 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 thatsolvepdepasses.Nris equal to the length of thelocation.xor any otherlocationfield. The function should evaluatefat these points.

For example, ifN= 3,fcould 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

f = [ x y + u ( 1 ) 1 + tanh ( u ( 1 ) / x ) + tanh ( u ( 3 ) / y ) ( 5 + u ( 3 ) ) x 2 + y 2 ]

Related Topics