Main Content

Specify Coefficients in PDE Modeler App

Coefficients for Scalar PDEs

To enter coefficients for your PDE, select PDE > PDE Specification.

Dialog box for specifying coefficients for elliptic, parabolic, hyperbolic, and eigenmodes types of scalar PDEs

Enter text expressions using these conventions:

  • xx-coordinate

  • yy-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 expression to represent a coefficient:

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

For elliptic problems, when you include u, ux, or uy, you must use the nonlinear solver. Select Solve > Parameters > Use nonlinear solver.

Note

  • Do not use quotes or unnecessary spaces in your entries. The parser can misinterpret a space as a vector separator, as when a MATLAB® vector uses a space to separate elements of a vector.

  • 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

Use fcoeff(x,y,t,sd) as the f coefficient in the parabolic solver.

Dialog box showing c=1, a=0, f=fcoeff(x,y,t,sd), d=1

The coefficient c is a 2-by-2 matrix. You can give 1-, 2-, 3-, or 4-element matrix expressions. Separate the expressions for elements by spaces. These expressions mean:

  • 1-element expression: (c00c)

  • 2-element expression: (c(1)00c(2))

  • 3-element expression: (c(1)c(2)c(2)c(3))

  • 4-element expression: (c(1)c(3)c(2)c(4))

For example, c is a symmetric matrix with constant diagonal entries and cos(xy) as the off-diagonal terms:

1.1 cos(x.*y) 5.5(1)

Dialog box showing c=1.1 cos(x.*y) 5.5, a=0, f=10, d=1

This corresponds to coefficients for the parabolic equation

ut·((1.1cos(xy)cos(xy)5.5)u)=10.

Coefficients for Systems of PDEs

You can enter coefficients for a system with N = 2 equations in the PDE Modeler app. To do so, open the PDE Modeler app and select Generic System.

View of the drop-down list for selecting particular applications: generic scalar, generic system, structural mechanics - plane stress, structural mechanics - plane strain, electrostatics, magnetostatics, AC power electromagnetics, conductive media DC. heat transfer, and diffusion

Then select PDE > PDE Specification.

Dialog box for specifying coefficients for elliptic, parabolic, hyperbolic, and eigenmodes types of systems of PDEs

Enter character expressions for coefficients using the form in Coefficients for Scalar PDEs, with additional options for nonlinear equations. The additional options are:

  • Represent the ith component of the solution u using 'u(i)' for i = 1 or 2.

  • Similarly, represent the ith components of the gradients of the solution u using 'ux(i)' and 'uy(i)' for i = 1 or 2.

Note

For elliptic problems, when you include coefficients u(i), ux(i), or uy(i), you must use the nonlinear solver. Select Solve > Parameters > Use nonlinear solver.

Do not use quotes or unnecessary spaces in your entries.

For higher-dimensional systems, do not use the PDE Modeler app. Represent your problem coefficients at the command line.

You can enter scalars into the c matrix, corresponding to these equations:

·(c11u1)·(c12u2)+a11u1+a12u2=f1·(c21u1)·(c22u2)+a21u1+a22u2=f2

If you need matrix versions of any of the cij coefficients, enter expressions separated by spaces. You can give 1-, 2-, 3-, or 4-element matrix expressions. These mean:

  • 1-element expression: (c00c)

  • 2-element expression: (c(1)00c(2))

  • 3-element expression: (c(1)c(2)c(2)c(3))

  • 4-element expression: (c(1)c(3)c(2)c(4))

For example, these expressions show one of each type (1-, 2-, 3-, and 4-element expressions)

Dialog box with the matrix coefficients values separated by spaces

These expressions correspond to the equations

·((4+cos(xy)004+cos(xy))u1)·((1001)u2)=1·((.1.2.2.3)u1)·((7.6.5exp(xy))u2)=2

Coefficients That Depend on Time and Space

This example shows how to enter time- and coordinate-dependent coefficients in the PDE Modeler app.

Solve the parabolic PDE,

dut(cu)+au=f

with the following coefficients:

  • d = 5

  • a = 0

  • f is a linear ramp up to 10, holds at 10, then ramps back down to 0:

    f=10*{10t0t0.110.1t0.91010t0.9t1

  • c = 1 +.x2 + y2

To solve this equation in the PDE Modeler app, follow these steps:

  1. Write the file framp.m and save it on your MATLAB path.

    function f = framp(t)
    
    if t <= 0.1
        f = 10*t;
    elseif t <= 0.9
        f = 1;
    else
        f = 10-10*t;
    end
    f = 10*f;
  2. Open the PDE Modeler app by using the pdeModeler command.

  3. Display grid lines by selecting Options > Grid.

  4. Align new shapes to the grid lines by selecting Options > Snap.

  5. Draw a rectangle with the corners at (-1,-0.4), (-1,0.4), (1,0.4), and (1,-0.4). To do this, first click the Rectangle button. Then click one of the corners using the left mouse button and drag to draw a rectangle.

  6. Draw a circle with the radius 0.2 and the center at (0.5,0). To do this, first click the Ellipse with the marked center button. Then right-click the origin and drag to draw a circle. Right-clicking constrains the shape you draw so that it is a circle rather than an ellipse. If the circle is not a perfect unit circle, double-click it. In the resulting dialog box, specify the exact center location and radius of the circle.

  7. Model the geometry by entering R1-C1 in the Set formula field.

    Geometry consisting of a circle inside a rectangle

  8. Check that the application mode is set to Generic Scalar.

  9. Specify the boundary conditions. To do this, switch to the boundary mode by selecting Boundary > Boundary Mode. Use Shift+click to select several boundaries. Then select Boundary > Specify Boundary Conditions.

    • For the rectangle, use the Dirichlet boundary condition with h = 1 and r = t*(x-y).

    • For the circle, use the Neumann boundary condition with g = x.^2+y.^2 and q = 1.

  10. Specify the coefficients by selecting PDE > PDE Specification or clicking the partial derivative button on the toolbar. Select the Parabolic type of PDE. Specify c = 1+x.^2+y.^2, a = 0, f = framp(t), and d = 5.

    Note

    Do not include quotes or spaces when you specify your coefficients the PDE Modeler app. The parser interprets all inputs as vectors of characters. It can misinterpret a space as a vector separator, as when a MATLAB vector uses a space to separate elements of a vector.

  11. Initialize the mesh by selecting Mesh > Initialize Mesh.

  12. Refine the mesh twice by selecting Mesh > Refine Mesh.

  13. Improve the triangle quality by selecting Mesh > Jiggle Mesh.

    Meshed geometry

  14. Set the initial value and the solution time. To do this, select Solve > Parameters.

    In the resulting dialog box, set the time to linspace(0,1,50) and the initial value u(t0) to 0.

  15. Solve the equation by selecting Solve > Solve PDE or clicking the partial derivative with the green triangle button on the toolbar.

    Solution plot

  16. Visualize the solution as a 3-D static plot. To do this:

    1. Select Plot > Parameters.

    2. In the resulting dialog box, select the Color and Height (3-D plot) options.

    3. Select the Show mesh option.

    4. Change the colormap to jet by using the corresponding drop-down menu in the same dialog box.

    Resulting plot with the mesh