Specify Scalar PDE Coefficients in String Form

Write a text expression using these conventions:

  • 'x'x-coordinate

  • 'y'y-coordinate

  • 'z'z-coordinate (3-D geometry)

  • 'u' — Solution of equation

  • 'ux' — Derivative of u in the x-direction

  • 'uy' — Derivative of u in the y-direction

  • 'uz' — Derivative of u in the z-direction (3-D geometry)

  • 't' — Time (parabolic and hyperbolic equations)

  • 'sd' — Subdomain number (not used in 3-D geometry)

For example, you could use this string to represent a coefficient:

'(x+y)./(x.^2 + y.^2 + 1) + 3 + sin(t)./(1+u.^4)'

    Note:   Use .*, ./, and .^ for multiplication, division, and exponentiation operations. The text expressions operate on row vectors, so the operations must make sense for row vectors. For 2-D geometry, the row vectors are the values at the triangle centroids in the mesh.

You can write MATLAB® functions for coefficients as well as plain text expressions. For example, suppose your coefficient f is given by the file fcoeff.m:

function f = fcoeff(x,y,t,sd)

f = (x.*y)./(1+x.^2+y.^2); % f on subdomain 1
f = f + log(1+t); % include time
r = (sd == 2); % subdomain 2
f2 = cos(x+y); % coefficient on subdomain 2 
f(r) = f2(r); % f on subdomain 2

Represent this function in the parabolic solver, for example:

u1 = parabolic(u0,tlist,b,p,e,t,c,a,'fcoeff(x,y,t,sd)',d)

    Caution   In function form, t represents triangles, and time represents time. In string form, t represents time, and triangles do not enter into the form.

There is a simple way to write a text expression for multiple subdomains without using 'sd' or a function. Separate the formulas for the different subdomains with the '!' character. Generally use the same number of expressions as subdomains. However, if an expression does not depend on the subdomain number, you can give just one expression.

For example, an expression for an input (a, c, f, or d) with three subdomains:


The coefficient c is a 2-by-2 matrix. You can give c in any of the following forms:

  • Scalar or single string — The software interprets c as a diagonal matrix:


  • Two-element column vector or two-row text array — The software interprets c as a diagonal matrix:


  • Three-element column vector or three-row text array — The software interprets c as a symmetric matrix:


  • Four-element column vector or four-row text array — The software interprets c as a full matrix:


For example, c as a symmetric matrix with cos(xy) on the off-diagonal terms:

c = char('x.^2+y.^2',...

To include subdomains separated by '!', include the '!' in each row. For example,

c = char('1+x.^2+y.^2!x.^2+y.^2',...

    Caution   Do not include spaces in your coefficient strings in the PDE app. The string parser can misinterpret a space as a vector separator, as when a MATLAB vector uses a space to separate elements of a vector.

For elliptic problems, when you include 'u', 'ux', 'uy', or 'uz', you must use the pdenonlin solver instead of assempde. In the PDE app, select Solve > Parameters > Use nonlinear solver.

Related Examples

More About

Was this topic helpful?