Documentation

Scalar PDE Coefficients in String Form

Write a text expression using these conventions:

  • 'x'x-coordinate

  • 'y'y-coordinate

  • 'u' — Solution of equation

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

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

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

  • 'sd' — Subdomain number

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. 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:

'2+tanh(x.*y)!cosh(x)./(1+x.^2+y.^2)!x.^2+y.^2'

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:

    (c00c)

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

    (c(1)00c(2))

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

    (c(1)c(2)c(2)c(3))

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

    (c(1)c(3)c(2)c(4))

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

c = char('x.^2+y.^2',...
    'cos(x.*y)',...
    'u./(1+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',...
    'cos(x.*y)!sin(x.*y)',...
    'u./(1+x.^2+y.^2)!u.*(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', or 'uy', 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?