Accelerating the pace of engineering and science

# assempde

Assemble stiffness matrix and right side of PDE problem

## Syntax

```u = assempde(b,p,e,t,c,a,f)
u = assempde(b,p,e,t,c,a,f,u0)
u = assempde(b,p,e,t,c,a,f,u0,time)
u = assempde(b,p,e,t,c,a,f,time)
[K,F] = assempde(b,p,e,t,c,a,f)
[K,F] = assempde(b,p,e,t,c,a,f,u0)
[K,F] = assempde(b,p,e,t,c,a,f,u0,time)
[K,F] = assempde(b,p,e,t,c,a,f,u0,time,sdl)
[K,F] = assempde(b,p,e,t,c,a,f,time)
[K,F] = assempde(b,p,e,t,c,a,f,time,sdl)
[K,F,B,ud] = assempde(b,p,e,t,c,a,f)
[K,F,B,ud] = assempde(b,p,e,t,c,a,f,u0)
[K,F,B,ud] = assempde(b,p,e,t,c,a,f,u0,time)
[K,F,B,ud] = assempde(b,p,e,t,c,a,f,time)
[K,M,F,Q,G,H,R] = assempde(b,p,e,t,c,a,f)
[K,M,F,Q,G,H,R] = assempde(b,p,e,t,c,a,f,u0)
[K,M,F,Q,G,H,R] = assempde(b,p,e,t,c,a,f,u0,time)
[K,M,F,Q,G,H,R] = assempde(b,p,e,t,c,a,f,u0,time,sdl)
[K,M,F,Q,G,H,R] = assempde(b,p,e,t,c,a,f,time)
[K,M,F,Q,G,H,R] = assempde(b,p,e,t,c,a,f,time,sdl)
u = assempde(K,M,F,Q,G,H,R)
[K1,F1] = assempde(K,M,F,Q,G,H,R)
[K1,F1,B,ud] = assempde(K,M,F,Q,G,H,R)

```

## Description

assempde is the basic Partial Differential Equation Toolbox™ function. It assembles a PDE problem by using the FEM formulation described in Elliptic Equations. The command assempde assembles the scalar PDE problem

$-\nabla \cdot \left(c\nabla u\right)+au=f,$

for (x,y) ∊ Ω, or the system PDE problem

$-\nabla \cdot \left(c\otimes \nabla u\right)+au=f.$

The command can optionally produce a solution to the PDE problem.

For the scalar case the solution vector u is represented as a column vector of solution values at the corresponding node points from p. For a system of dimension N with np node points, the first np values of u describe the first component of u, the following np values of u describe the second component of u, and so on. Thus, the components of u are placed in the vector u as N blocks of node point values.

u = assempde(b,p,e,t,c,a,f) assembles and solves the PDE problem by eliminating the Dirichlet boundary conditions from the system of linear equations.

[K,F] = assempde(b,p,e,t,c,a,f) assembles the PDE problem by approximating the Dirichlet boundary condition with stiff springs (see Systems of PDEs for details). K and F are the stiffness matrix and right-hand side, respectively. The solution to the FEM formulation of the PDE problem is u = K\F.

[K,F,B,ud] = assempde(b,p,e,t,c,a,f) assembles the PDE problem by eliminating the Dirichlet boundary conditions from the system of linear equations. u1 = K\F returns the solution on the non-Dirichlet points. The solution to the full PDE problem can be obtained as the MATLAB® expression u = B*u1+ud.

[K,M,F,Q,G,H,R] = assempde(b,p,e,t,c,a,f) gives a split representation of the PDE problem.

u = assempde(K,M,F,Q,G,H,R) collapses the split representation into the single matrix/vector form, and then solves the PDE problem by eliminating the Dirichlet boundary conditions from the system of linear equations.

[K1,F1] = assempde(K,M,F,Q,G,H,R) collapses the split representation into the single matrix/vector form, by fixing the Dirichlet boundary condition with large spring constants.

[K1,F1,B,ud] = assempde(K,M,F,Q,G,H,R) collapses the split representation into the single matrix/vector form by eliminating the Dirichlet boundary conditions from the system of linear equations.

b describes the boundary conditions of the PDE problem. For the recommended way of specifying boundary conditions, see Steps to Specify a Boundary Conditions Object. For all methods of specifying boundary conditions, see Boundary Condition Specification.

The geometry of the PDE problem is given by the mesh data p, e, and t. For details on the mesh data representation, see initmesh.

The optional list of subdomain labels, sdl, restricts the assembly process to the subdomains denoted by the labels in the list. The optional input arguments u0 and time are used for the nonlinear solver and time stepping algorithms, respectively. The tentative input solution vector u0 has the same format as u.

## Examples

### Example 1

Solve the equation Δu = 1 on the geometry defined by the L-shaped membrane. Use Dirichlet boundary conditions u = 0 on ∂Ω. Finally plot the solution.

```[p,e,t] = initmesh('lshapeg','Hmax',0.2);
[p,e,t] = refinemesh('lshapeg',p,e,t);
u = assempde('lshapeb',p,e,t,1,0,1);
pdesurf(p,t,u)```

### Example 2

Consider Poisson's equation on the unit circle with unit point source at the origin. The exact solution

$u=-\frac{1}{2\pi }\mathrm{log}\left(r\right)$

is known for this problem. We define the function f = circlef(p,t,u,time) for computing the right-hand side. circlef returns zero for all triangles except for the one located at the origin; for that triangle it returns 1/a, where a is the triangle area. pdedemo7 executes an adaptive solution for this problem.