# Documentation

### This is machine translation

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

## Solve PDEs with Initial Conditions

 Note:   THIS PAGE DESCRIBES THE LEGACY WORKFLOW. New features might not be compatible with the legacy workflow. For the corresponding step in the recommended workflow, see Set Initial Conditions.

### What Are Initial Conditions?

Initial conditions has two meanings:

• For the `parabolic` and `hyperbolic` solvers, the initial condition `u0` is the solution u at the initial time. You must specify the initial condition for these solvers. Pass the initial condition in the first argument or arguments.

```u = parabolic(u0,... or u = hyperbolic(u0,ut0,...```

For the `hyperbolic` solver, you must also specify `ut0`, which is the value of the derivative of u with respect to time at the initial time. `ut0` has the same form as `u0`.

• For nonlinear elliptic problems, the initial condition `u0` is a guess or approximation of the solution u at the initial iteration of the `pdenonlin` nonlinear solver. You pass `u0` in the `'U0'` name-value pair.

`u = pdenonlin(b,p,e,t,c,a,f,'U0',u0)`

If you do not specify initial conditions, `pdenonlin` uses the zero function for the initial iteration.

### Constant Initial Conditions

You can specify initial conditions as a constant by passing a scalar or character vector.

• For scalar problems or systems of equations, give a scalar as the initial condition. For example, set `u0` to `5` for an initial condition of 5 in every component.

• For systems of N equations, give a character vector initial condition with N rows. For example, if there are N = 3 equations, you can give initial conditions `u0` = `char('3','-3','0')`.

### Initial Conditions in Character Form

You can specify text expressions for the initial conditions. The initial conditions are functions of x and y alone, and, for 3-D problems, z. The text expressions represent vectors at nodal points, so use `.*` for multiplication, `./` for division, and `.^` for exponentiation.

For example, if you have an initial condition

`$u\left(x,y\right)=\frac{xy\mathrm{cos}\left(x\right)}{1+{x}^{2}+{y}^{2}}$`

then you can use this expression for the initial condition.

`'x.*y.*cos(x)./(1 + x.^2 + y.^2)'`

For a system of N > 1 equations, use a text array with one row for each component, such as

```char('x.^2 + 5*cos(x.*y)',... 'tanh(x.*y)./(1 + z.^2)')```

### Initial Conditions at Mesh Nodes

Pass `u0` as a column vector of values at the mesh nodes. The nodes are either `model.Mesh.Nodes`, or the `p` data from `initmesh` or `meshToPet`. See Mesh Data.

 Tip:   For reliability, the initial conditions and boundary conditions should be consistent.

The size of the column vector `u0` depends on the number of equations, N, and on the number of nodes in the mesh, `Np`.

For scalar u, specify a column vector of length `Np`. The value of element `k` corresponds to the node `p(k)`.

For a system of N equations, specify a column vector of N*`Np` elements. The first `Np` elements contain the values of component 1, where the value of element `k` corresponds to node `p(k)`. The next `Np` points contain the values of component 2, etc. It can be convenient to first represent the initial conditions `u0` as an `Np`-by-`N` matrix, where the first column contains entries for component 1, the second column contains entries for component 2, etc. The final representation of the initial conditions is `u0(:)`.

For example, suppose you have a function `myfun(x,y)` that calculates the value of the initial condition `u0(x,y)` as a row vector of length N for a 2-D problem. Suppose that `p` is the usual mesh node data (see Mesh Data). Compute the initial conditions for all mesh nodes `p`.

```% Assume N and p exist; N = 1 for a scalar problem np = size(p,2); % Number of mesh points u0 = zeros(np,N); % Allocate initial matrix for k = 1:np x = p(1,k); y = p(2,k); u0(k,:) = myfun(x,y); % Fill in row k end u0 = u0(:); % Convert to column form```

Specify `u0` as the initial condition.