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.
Pass u0
as a column vector of values at the
points p
in the usual p
, t
, e
mesh.
See Mesh Data. You can also pass
a scalar, which means the initial condition is a constant value.
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 points in the mesh, N_{p}
.
For scalar u, specify a column vector of
length N_{p}
. The value of
element k
corresponds to the point p(k)
.
For a system of N equations, specify a column
vector of N*N_{p}
elements.
The first N_{p}
elements contain
the values of component 1, where the value of element k
corresponds
to point p(k)
. The next N_{p}
points
contain the values of component 2, etc. It can be convenient to first
represent the initial conditions u0
as an N_{p}
-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. Suppose that p
is
the usual mesh point data (see Mesh Data).
Compute the initial conditions for all mesh points 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.
For the parabolic
and hyperbolic
solvers
with scalar problems, you can also specify text expressions for the
initial conditions. The initial conditions are functions of x and y alone,
and, for 3-D problems, z.
For example, if you have an initial condition
$$u(x,y)=\frac{xy\mathrm{cos}(x)}{1+{x}^{2}+{y}^{2}},$$
then you can use this expression for the initial condition.
'x.*y.*cos(x)./(1+x.^2+y.^2)'
hyperbolic
| parabolic
| pdenonlin