This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

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 PDE 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 could be:

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


    solvepde passes the location and state structures to fcoeffunction. The 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.

    Pass the coefficient to specifyCoefficients as a function handle, such as

    • location is a structure with these fields:

      • location.x

      • location.y

      • location.z

      • location.subdomain

      The fields x, y, and z represent the x-, y-, and z- coordinates of points for which your function calculates coefficient values. The subdomain 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.time

      The state.u field represents the current value of the solution u. The state.ux,, and 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. The state.time field is a scalar representing time for time-dependent models.

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(,:));
f(3,:) = (5 + state.u(3,:)).*sqrt(location.x.^2 + location.y.^2);

This represents the coefficient function


Related Topics