PDF version (NAG web site
, 64bit version, 64bit version)
NAG Toolbox: nag_pde_1d_parab_fd (d03pc)
Purpose
nag_pde_1d_parab_fd (d03pc) integrates a system of linear or nonlinear parabolic partial differential equations (PDEs) in one space variable. The spatial discretization is performed using finite differences, and the method of lines is employed to reduce the PDEs to a system of ordinary differential equations (ODEs). The resulting system is solved using a backward differentiation formula method.
Syntax
[
ts,
u,
rsave,
isave,
ind,
user,
cwsav,
lwsav,
iwsav,
rwsav,
ifail] = d03pc(
m,
ts,
tout,
pdedef,
bndary,
u,
x,
acc,
rsave,
isave,
itask,
itrace,
ind,
cwsav,
lwsav,
iwsav,
rwsav, 'npde',
npde, 'npts',
npts, 'user',
user)
[
ts,
u,
rsave,
isave,
ind,
user,
cwsav,
lwsav,
iwsav,
rwsav,
ifail] = nag_pde_1d_parab_fd(
m,
ts,
tout,
pdedef,
bndary,
u,
x,
acc,
rsave,
isave,
itask,
itrace,
ind,
cwsav,
lwsav,
iwsav,
rwsav, 'npde',
npde, 'npts',
npts, 'user',
user)
Note: the interface to this routine has changed since earlier releases of the toolbox:
At Mark 22: 
lrsave and lisave were removed from the interface 
Description
nag_pde_1d_parab_fd (d03pc) integrates the system of parabolic equations:
where
${P}_{i,j}$,
${Q}_{i}$ and
${R}_{i}$ depend on
$x$,
$t$,
$U$,
${U}_{x}$ and the vector
$U$ is the set of solution values
and the vector
${U}_{x}$ is its partial derivative with respect to
$x$. Note that
${P}_{i,j}$,
${Q}_{i}$ and
${R}_{i}$ must not depend on
$\frac{\partial U}{\partial t}$.
The integration in time is from ${t}_{0}$ to ${t}_{\mathrm{out}}$, over the space interval $a\le x\le b$, where $a={x}_{1}$ and $b={x}_{{\mathbf{npts}}}$ are the leftmost and rightmost points of a userdefined mesh ${x}_{1},{x}_{2},\dots ,{x}_{{\mathbf{npts}}}$. The coordinate system in space is defined by the value of $m$;
$m=0$ for Cartesian coordinates,
$m=1$ for cylindrical polar coordinates and $m=2$ for spherical polar coordinates. The mesh should be chosen in accordance with the expected behaviour of the solution.
The system is defined by the functions
${P}_{i,j}$,
${Q}_{i}$ and
${R}_{i}$ which must be specified in
pdedef.
The initial values of the functions
$U\left(x,t\right)$ must be given at
$t={t}_{0}$. The functions
${R}_{i}$, for
$\mathit{i}=1,2,\dots ,{\mathbf{npde}}$, which may be thought of as fluxes, are also used in the definition of the boundary conditions for each equation. The boundary conditions must have the form
where
$x=a$ or
$x=b$.
The boundary conditions must be specified in
bndary.
The problem is subject to the following restrictions:
(i) 
${t}_{0}<{t}_{\mathrm{out}}$, so that integration is in the forward direction; 
(ii) 
${P}_{i,j}$,
${Q}_{i}$ and the flux ${R}_{i}$ must not depend on any time derivatives; 
(iii) 
the evaluation of the functions ${P}_{i,j}$,
${Q}_{i}$ and ${R}_{i}$ is done at the midpoints of the mesh intervals by calling the pdedef for each midpoint in turn. Any discontinuities in these functions must therefore be at one or more of the mesh points ${x}_{1},{x}_{2},\dots ,{x}_{{\mathbf{npts}}}$; 
(iv) 
at least one of the functions ${P}_{i,j}$ must be nonzero so that there is a time derivative present in the problem; and 
(v) 
if $m>0$ and ${x}_{1}=0.0$, which is the left boundary point, then it must be ensured that the PDE solution is bounded at this point. This can be done by either specifying the solution at $x=0.0$ or by specifying a zero flux there, that is ${\beta}_{i}=1.0$ and ${\gamma}_{i}=0.0$. See also Further Comments. 
The parabolic equations are approximated by a system of ODEs in time for the values of ${U}_{i}$ at mesh points. For simple problems in Cartesian coordinates, this system is obtained by replacing the space derivatives by the usual central, threepoint finite difference formula. However, for polar and spherical problems, or problems with nonlinear coefficients, the space derivatives are replaced by a modified threepoint formula which maintains secondorder accuracy. In total there are ${\mathbf{npde}}\times {\mathbf{npts}}$ ODEs in the time direction. This system is then integrated forwards in time using a backward differentiation formula method.
References
Berzins M (1990) Developments in the NAG Library software for parabolic equations Scientific Software Systems (eds J C Mason and M G Cox) 59–72 Chapman and Hall
Berzins M, Dew P M and Furzeland R M (1989) Developing software for timedependent problems using the method of lines and differentialalgebraic integrators Appl. Numer. Math. 5 375–397
Dew P M and Walsh J (1981) A set of library routines for solving parabolic equations in one space variable ACM Trans. Math. Software 7 295–314
Skeel R D and Berzins M (1990) A method for the spatial discretization of parabolic equations in one space variable SIAM J. Sci. Statist. Comput. 11(1) 1–32
Parameters
Compulsory Input Parameters
 1:
$\mathrm{m}$ – int64int32nag_int scalar

The coordinate system used:
 ${\mathbf{m}}=0$
 Indicates Cartesian coordinates.
 ${\mathbf{m}}=1$
 Indicates cylindrical polar coordinates.
 ${\mathbf{m}}=2$
 Indicates spherical polar coordinates.
Constraint:
${\mathbf{m}}=0$, $1$ or $2$.
 2:
$\mathrm{ts}$ – double scalar

The initial value of the independent variable $t$.
Constraint:
${\mathbf{ts}}<{\mathbf{tout}}$.
 3:
$\mathrm{tout}$ – double scalar

The final value of $t$ to which the integration is to be carried out.
 4:
$\mathrm{pdedef}$ – function handle or string containing name of mfile

pdedef must compute the functions
${P}_{i,j}$,
${Q}_{i}$ and
${R}_{i}$ which define the system of PDEs.
pdedef is called approximately midway between each pair of mesh points in turn by
nag_pde_1d_parab_fd (d03pc).
[p, q, r, ires, user] = pdedef(npde, t, x, u, ux, ires, user)
Input Parameters
 1:
$\mathrm{npde}$ – int64int32nag_int scalar

The number of PDEs in the system.
 2:
$\mathrm{t}$ – double scalar

The current value of the independent variable $t$.
 3:
$\mathrm{x}$ – double scalar

The current value of the space variable $x$.
 4:
$\mathrm{u}\left({\mathbf{npde}}\right)$ – double array

${\mathbf{u}}\left(\mathit{i}\right)$ contains the value of the component ${U}_{\mathit{i}}\left(x,t\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{npde}}$.
 5:
$\mathrm{ux}\left({\mathbf{npde}}\right)$ – double array

${\mathbf{ux}}\left(\mathit{i}\right)$ contains the value of the component $\frac{\partial {U}_{\mathit{i}}\left(x,t\right)}{\partial x}$, for $\mathit{i}=1,2,\dots ,{\mathbf{npde}}$.
 6:
$\mathrm{ires}$ – int64int32nag_int scalar

Set to $1\text{ or}1$.
 7:
$\mathrm{user}$ – Any MATLAB object
pdedef is called from
nag_pde_1d_parab_fd (d03pc) with the object supplied to
nag_pde_1d_parab_fd (d03pc).
Output Parameters
 1:
$\mathrm{p}\left({\mathbf{npde}},{\mathbf{npde}}\right)$ – double array

${\mathbf{p}}\left(\mathit{i},\mathit{j}\right)$ must be set to the value of ${P}_{\mathit{i},\mathit{j}}\left(x,t,U,{U}_{x}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{npde}}$ and $\mathit{j}=1,2,\dots ,{\mathbf{npde}}$.
 2:
$\mathrm{q}\left({\mathbf{npde}}\right)$ – double array

${\mathbf{q}}\left(\mathit{i}\right)$ must be set to the value of ${Q}_{\mathit{i}}\left(x,t,U,{U}_{x}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{npde}}$.
 3:
$\mathrm{r}\left({\mathbf{npde}}\right)$ – double array

${\mathbf{r}}\left(\mathit{i}\right)$ must be set to the value of ${R}_{\mathit{i}}\left(x,t,U,{U}_{x}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{npde}}$.
 4:
$\mathrm{ires}$ – int64int32nag_int scalar

Should usually remain unchanged. However, you may set
ires to force the integration function to take certain actions as described below:
 ${\mathbf{ires}}=2$
 Indicates to the integrator that control should be passed back immediately to the calling (sub)routine with the error indicator set to ${\mathbf{ifail}}={\mathbf{6}}$.
 ${\mathbf{ires}}=3$
 Indicates to the integrator that the current time step should be abandoned and a smaller time step used instead. You may wish to set ${\mathbf{ires}}=3$ when a physically meaningless input or output value has been generated. If you consecutively set ${\mathbf{ires}}=3$, then nag_pde_1d_parab_fd (d03pc) returns to the calling function with the error indicator set to ${\mathbf{ifail}}={\mathbf{4}}$.
 5:
$\mathrm{user}$ – Any MATLAB object
 5:
$\mathrm{bndary}$ – function handle or string containing name of mfile

bndary must compute the functions
${\beta}_{i}$ and
${\gamma}_{i}$ which define the boundary conditions as in equation
(3).
[beta, gamma, ires, user] = bndary(npde, t, u, ux, ibnd, ires, user)
Input Parameters
 1:
$\mathrm{npde}$ – int64int32nag_int scalar

The number of PDEs in the system.
 2:
$\mathrm{t}$ – double scalar

The current value of the independent variable $t$.
 3:
$\mathrm{u}\left({\mathbf{npde}}\right)$ – double array

${\mathbf{u}}\left(\mathit{i}\right)$ contains the value of the component
${U}_{\mathit{i}}\left(x,t\right)$ at the boundary specified by
ibnd, for
$\mathit{i}=1,2,\dots ,{\mathbf{npde}}$.
 4:
$\mathrm{ux}\left({\mathbf{npde}}\right)$ – double array

${\mathbf{ux}}\left(\mathit{i}\right)$ contains the value of the component
$\frac{\partial {U}_{\mathit{i}}\left(x,t\right)}{\partial x}$ at the boundary specified by
ibnd, for
$\mathit{i}=1,2,\dots ,{\mathbf{npde}}$.
 5:
$\mathrm{ibnd}$ – int64int32nag_int scalar

Determines the position of the boundary conditions.
 ${\mathbf{ibnd}}=0$
 bndary must set up the coefficients of the lefthand boundary, $x=a$.
 ${\mathbf{ibnd}}\ne 0$
 Indicates that bndary must set up the coefficients of the righthand boundary, $x=b$.
 6:
$\mathrm{ires}$ – int64int32nag_int scalar

Set to $1\text{ or}1$.
 7:
$\mathrm{user}$ – Any MATLAB object
bndary is called from
nag_pde_1d_parab_fd (d03pc) with the object supplied to
nag_pde_1d_parab_fd (d03pc).
Output Parameters
 1:
$\mathrm{beta}\left({\mathbf{npde}}\right)$ – double array

${\mathbf{beta}}\left(\mathit{i}\right)$ must be set to the value of
${\beta}_{\mathit{i}}\left(x,t\right)$ at the boundary specified by
ibnd, for
$\mathit{i}=1,2,\dots ,{\mathbf{npde}}$.
 2:
$\mathrm{gamma}\left({\mathbf{npde}}\right)$ – double array

${\mathbf{gamma}}\left(\mathit{i}\right)$ must be set to the value of
${\gamma}_{\mathit{i}}\left(x,t,U,{U}_{x}\right)$ at the boundary specified by
ibnd, for
$\mathit{i}=1,2,\dots ,{\mathbf{npde}}$.
 3:
$\mathrm{ires}$ – int64int32nag_int scalar

Should usually remain unchanged. However, you may set
ires to force the integration function to take certain actions as described below:
 ${\mathbf{ires}}=2$
 Indicates to the integrator that control should be passed back immediately to the calling (sub)routine with the error indicator set to ${\mathbf{ifail}}={\mathbf{6}}$.
 ${\mathbf{ires}}=3$
 Indicates to the integrator that the current time step should be abandoned and a smaller time step used instead. You may wish to set ${\mathbf{ires}}=3$ when a physically meaningless input or output value has been generated. If you consecutively set ${\mathbf{ires}}=3$, then nag_pde_1d_parab_fd (d03pc) returns to the calling function with the error indicator set to ${\mathbf{ifail}}={\mathbf{4}}$.
 4:
$\mathrm{user}$ – Any MATLAB object
 6:
$\mathrm{u}\left({\mathbf{npde}},{\mathbf{npts}}\right)$ – double array

The initial values of $U\left(x,t\right)$ at $t={\mathbf{ts}}$ and the mesh points
${\mathbf{x}}\left(\mathit{j}\right)$, for $\mathit{j}=1,2,\dots ,{\mathbf{npts}}$.
 7:
$\mathrm{x}\left({\mathbf{npts}}\right)$ – double array

The mesh points in the spatial direction. ${\mathbf{x}}\left(1\right)$ must specify the lefthand boundary, $a$, and ${\mathbf{x}}\left({\mathbf{npts}}\right)$ must specify the righthand boundary, $b$.
Constraint:
${\mathbf{x}}\left(1\right)<{\mathbf{x}}\left(2\right)<\cdots <{\mathbf{x}}\left({\mathbf{npts}}\right)$.
 8:
$\mathrm{acc}$ – double scalar

A positive quantity for controlling the local error estimate in the time integration. If
$E\left(i,j\right)$ is the estimated error for
${U}_{i}$ at the
$j$th mesh point, the error test is:
Constraint:
${\mathbf{acc}}>0.0$.
 9:
$\mathrm{rsave}\left(\mathit{lrsave}\right)$ – double array

lrsave, the dimension of the array, must satisfy the constraint
$\mathit{lrsave}\ge \left(6\times {\mathbf{npde}}+10\right)\times {\mathbf{npde}}\times {\mathbf{npts}}+\left(3\times {\mathbf{npde}}+21\right)\times {\mathbf{npde}}+\phantom{\rule{0ex}{0ex}}7\times {\mathbf{npts}}+54$.
If
${\mathbf{ind}}=0$,
rsave need not be set on entry.
If
${\mathbf{ind}}=1$,
rsave must be unchanged from the previous call to the function because it contains required information about the iteration.
 10:
$\mathrm{isave}\left(\mathit{lisave}\right)$ – int64int32nag_int array

lisave, the dimension of the array, must satisfy the constraint
$\mathit{lisave}\ge {\mathbf{npde}}\times {\mathbf{npts}}+24$.
If
${\mathbf{ind}}=0$,
isave need not be set on entry.
If
${\mathbf{ind}}=1$,
isave must be unchanged from the previous call to the function because it contains required information about the iteration. In particular:
 ${\mathbf{isave}}\left(1\right)$
 Contains the number of steps taken in time.
 ${\mathbf{isave}}\left(2\right)$
 Contains the number of residual evaluations of the resulting ODE system used. One such evaluation involves computing the PDE functions at all the mesh points, as well as one evaluation of the functions in the boundary conditions.
 ${\mathbf{isave}}\left(3\right)$
 Contains the number of Jacobian evaluations performed by the time integrator.
 ${\mathbf{isave}}\left(4\right)$
 Contains the order of the last backward differentiation formula method used.
 ${\mathbf{isave}}\left(5\right)$
 Contains the number of Newton iterations performed by the time integrator. Each iteration involves an ODE residual evaluation followed by a backsubstitution using the $LU$ decomposition of the Jacobian matrix.
 11:
$\mathrm{itask}$ – int64int32nag_int scalar

Specifies the task to be performed by the ODE integrator.
 ${\mathbf{itask}}=1$
 Normal computation of output values u at $t={\mathbf{tout}}$.
 ${\mathbf{itask}}=2$
 One step and return.
 ${\mathbf{itask}}=3$
 Stop at first internal integration point at or beyond $t={\mathbf{tout}}$.
Constraint:
${\mathbf{itask}}=1$, $2$ or $3$.
 12:
$\mathrm{itrace}$ – int64int32nag_int scalar

The level of trace information required from
nag_pde_1d_parab_fd (d03pc) and the underlying ODE solver.
itrace may take the value
$1$,
$0$,
$1$,
$2$ or
$3$.
 ${\mathbf{itrace}}=1$
 No output is generated.
 ${\mathbf{itrace}}=0$
 Only warning messages from the PDE solver are printed on the current error message unit (see nag_file_set_unit_error (x04aa)).
 ${\mathbf{itrace}}>0$
 Output from the underlying ODE solver is printed on the current advisory message unit (see nag_file_set_unit_advisory (x04ab)). This output contains details of Jacobian entries, the nonlinear iteration and the time integration during the computation of the ODE system.
If ${\mathbf{itrace}}<1$, then $1$ is assumed and similarly if ${\mathbf{itrace}}>3$, then $3$ is assumed.
The advisory messages are given in greater detail as
itrace increases. You are advised to set
${\mathbf{itrace}}=0$, unless you are experienced with
Subchapter D02M–N.
 13:
$\mathrm{ind}$ – int64int32nag_int scalar

Indicates whether this is a continuation call or a new integration.
 ${\mathbf{ind}}=0$
 Starts or restarts the integration in time.
 ${\mathbf{ind}}=1$
 Continues the integration after an earlier exit from the function. In this case, only the arguments tout and ifail should be reset between calls to nag_pde_1d_parab_fd (d03pc).
Constraint:
${\mathbf{ind}}=0$ or $1$.
 14:
$\mathrm{cwsav}\left(10\right)$ – cell array of strings

If
${\mathbf{ind}}=0$,
cwsav need not be set on entry.
If
${\mathbf{ind}}=1$,
cwsav must be unchanged from the previous call to the function.
 15:
$\mathrm{lwsav}\left(100\right)$ – logical array

If
${\mathbf{ind}}=0$,
lwsav need not be set on entry.
If
${\mathbf{ind}}=1$,
lwsav must be unchanged from the previous call to the function.
 16:
$\mathrm{iwsav}\left(505\right)$ – int64int32nag_int array

If
${\mathbf{ind}}=0$,
iwsav need not be set on entry.
If
${\mathbf{ind}}=1$,
iwsav must be unchanged from the previous call to the function.
 17:
$\mathrm{rwsav}\left(1100\right)$ – double array

If
${\mathbf{ind}}=0$,
rwsav need not be set on entry.
If
${\mathbf{ind}}=1$,
rwsav must be unchanged from the previous call to the function.
Optional Input Parameters
 1:
$\mathrm{npde}$ – int64int32nag_int scalar

Default:
the first dimension of the array
u.
The number of PDEs in the system to be solved.
Constraint:
${\mathbf{npde}}\ge 1$.
 2:
$\mathrm{npts}$ – int64int32nag_int scalar

Default:
the dimension of the array
x and the second dimension of the array
u. (An error is raised if these dimensions are not equal.)
The number of mesh points in the interval $\left[a,b\right]$.
Constraint:
${\mathbf{npts}}\ge 3$.
 3:
$\mathrm{user}$ – Any MATLAB object
user is not used by
nag_pde_1d_parab_fd (d03pc), but is passed to
pdedef and
bndary. Note that for large objects it may be more efficient to use a global variable which is accessible from the mfiles than to use
user.
Output Parameters
 1:
$\mathrm{ts}$ – double scalar

The value of
$t$ corresponding to the solution values in
u. Normally
${\mathbf{ts}}={\mathbf{tout}}$.
 2:
$\mathrm{u}\left({\mathbf{npde}},{\mathbf{npts}}\right)$ – double array

${\mathbf{u}}\left(\mathit{i},\mathit{j}\right)$ will contain the computed solution at $t={\mathbf{ts}}$.
 3:
$\mathrm{rsave}\left(\mathit{lrsave}\right)$ – double array

If
${\mathbf{ind}}=1$,
rsave must be unchanged from the previous call to the function because it contains required information about the iteration.
 4:
$\mathrm{isave}\left(\mathit{lisave}\right)$ – int64int32nag_int array

If
${\mathbf{ind}}=1$,
isave must be unchanged from the previous call to the function because it contains required information about the iteration. In particular:
 ${\mathbf{isave}}\left(1\right)$
 Contains the number of steps taken in time.
 ${\mathbf{isave}}\left(2\right)$
 Contains the number of residual evaluations of the resulting ODE system used. One such evaluation involves computing the PDE functions at all the mesh points, as well as one evaluation of the functions in the boundary conditions.
 ${\mathbf{isave}}\left(3\right)$
 Contains the number of Jacobian evaluations performed by the time integrator.
 ${\mathbf{isave}}\left(4\right)$
 Contains the order of the last backward differentiation formula method used.
 ${\mathbf{isave}}\left(5\right)$
 Contains the number of Newton iterations performed by the time integrator. Each iteration involves an ODE residual evaluation followed by a backsubstitution using the $LU$ decomposition of the Jacobian matrix.
 5:
$\mathrm{ind}$ – int64int32nag_int scalar

${\mathbf{ind}}=1$.
 6:
$\mathrm{user}$ – Any MATLAB object
 7:
$\mathrm{cwsav}\left(10\right)$ – cell array of strings

If
${\mathbf{ind}}=1$,
cwsav must be unchanged from the previous call to the function.
 8:
$\mathrm{lwsav}\left(100\right)$ – logical array

If
${\mathbf{ind}}=1$,
lwsav must be unchanged from the previous call to the function.
 9:
$\mathrm{iwsav}\left(505\right)$ – int64int32nag_int array

If
${\mathbf{ind}}=1$,
iwsav must be unchanged from the previous call to the function.
 10:
$\mathrm{rwsav}\left(1100\right)$ – double array

If
${\mathbf{ind}}=1$,
rwsav must be unchanged from the previous call to the function.
 11:
$\mathrm{ifail}$ – int64int32nag_int scalar
${\mathbf{ifail}}={\mathbf{0}}$ unless the function detects an error (see
Error Indicators and Warnings).
Error Indicators and Warnings
Errors or warnings detected by the function:
Cases prefixed with W are classified as warnings and
do not generate an error of type NAG:error_n. See nag_issue_warnings.
 ${\mathbf{ifail}}=1$

On entry,  ${\mathbf{tout}}\le {\mathbf{ts}}$, 
or  ${\mathbf{tout}}{\mathbf{ts}}$ is too small, 
or  ${\mathbf{itask}}\ne 1$, $2$ or $3$, 
or  ${\mathbf{m}}\ne 0$, $1$ or $2$, 
or  ${\mathbf{m}}>0$ and ${\mathbf{x}}\left(1\right)<0.0$, 
or  $\text{the mesh points}{\mathbf{x}}\left(i\right)$ are not ordered, 
or  ${\mathbf{npts}}<3$, 
or  ${\mathbf{npde}}<1$, 
or  ${\mathbf{acc}}\le 0.0$, 
or  ${\mathbf{ind}}\ne 0$ or $1$, 
or  lrsave is too small, 
or  lisave is too small. 
 W ${\mathbf{ifail}}=2$

The underlying ODE solver cannot make any further progress across the integration range from the current point
$t={\mathbf{ts}}$ with the supplied value of
acc. The components of
u contain the computed values at the current point
$t={\mathbf{ts}}$.
 W ${\mathbf{ifail}}=3$

In the underlying ODE solver, there were repeated errors or corrector convergence test failures on an attempted step, before completing the requested task. The problem may have a singularity or
acc is too small for the integration to continue. Integration was successful as far as
$t={\mathbf{ts}}$.
 ${\mathbf{ifail}}=4$

In setting up the ODE system, the internal initialization function was unable to initialize the derivative of the ODE system. This could be due to the fact that
ires was repeatedly set to
$3$ in at least
pdedef or
bndary, when the residual in the underlying ODE solver was being evaluated.
 ${\mathbf{ifail}}=5$

In solving the ODE system, a singular Jacobian has been encountered. You should check your problem formulation.
 W ${\mathbf{ifail}}=6$

When evaluating the residual in solving the ODE system,
ires was set to
$2$ in at least
pdedef or
bndary. Integration was successful as far as
$t={\mathbf{ts}}$.
 ${\mathbf{ifail}}=7$

The value of
acc is so small that the function is unable to start the integration in time.
 ${\mathbf{ifail}}=8$

In one of
pdedef or
bndary,
ires was set to an invalid value.
 ${\mathbf{ifail}}=9$ (nag_ode_ivp_stiff_imp_revcom (d02nn))

A serious error has occurred in an internal call to the specified function. Check the problem specification and all arguments and array dimensions. Setting
${\mathbf{itrace}}=1$ may provide more information. If the problem persists, contact
NAG.
 W ${\mathbf{ifail}}=10$

The required task has been completed, but it is estimated that a small change in
acc is unlikely to produce any change in the computed solution. (Only applies when you are not operating in one step mode, that is when
${\mathbf{itask}}\ne 2$.)
 ${\mathbf{ifail}}=11$

An error occurred during Jacobian formulation of the ODE system (a more detailed error description may be directed to the current error message unit).
 ${\mathbf{ifail}}=12$

Not applicable.
 ${\mathbf{ifail}}=13$

Not applicable.
 ${\mathbf{ifail}}=14$

The flux function ${R}_{i}$ was detected as depending on time derivatives, which is not permissible.
 ${\mathbf{ifail}}=99$
An unexpected error has been triggered by this routine. Please
contact
NAG.
 ${\mathbf{ifail}}=399$
Your licence key may have expired or may not have been installed correctly.
 ${\mathbf{ifail}}=999$
Dynamic memory allocation failed.
Accuracy
nag_pde_1d_parab_fd (d03pc) controls the accuracy of the integration in the time direction but not the accuracy of the approximation in space. The spatial accuracy depends on both the number of mesh points and on their distribution in space. In the time integration only the local error over a single step is controlled and so the accuracy over a number of steps cannot be guaranteed. You should therefore test the effect of varying the accuracy argument,
acc.
Further Comments
nag_pde_1d_parab_fd (d03pc) is designed to solve parabolic systems (possibly including some elliptic equations) with secondorder derivatives in space. The argument specification allows you to include equations with only firstorder derivatives in the space direction but there is no guarantee that the method of integration will be satisfactory for such systems. The position and nature of the boundary conditions in particular are critical in defining a stable problem. It may be advisable in such cases to reduce the whole system to firstorder and to use the Keller box scheme function
nag_pde_1d_parab_keller (d03pe).
The time taken depends on the complexity of the parabolic system and on the accuracy requested.
Example
We use the example given in
Dew and Walsh (1981) which consists of an ellipticparabolic pair of PDEs. The problem was originally derived from a single thirdorder in space PDE. The elliptic equation is
and the parabolic equation is
where
$\left(r,t\right)\in \left[0,1\right]\times \left[0,1\right]$. The boundary conditions are given by
and
The first of these boundary conditions implies that the flux term in the second PDE,
$\left(\frac{\partial {U}_{2}}{\partial r}{U}_{2}{U}_{1}\right)$, is zero at $r=0$.
The initial conditions at
$t=0$ are given by
The value
$\alpha =1$ was used in the problem definition. A mesh of
$20$ points was used with a circular mesh spacing to cluster the points towards the righthand side of the spatial interval,
$r=1$.
Open in the MATLAB editor:
d03pc_example
function d03pc_example
fprintf('d03pc example results\n\n');
global alpha;
npde = 2;
npts = 20;
intpts = 6;
itype = int64(1);
neqn = npde*npts;
lisave = neqn + 24;
nwk = (10 + 6*npde)*neqn;
lrsave = nwk + (21 + 3*npde)*npde + 7*npts + 54;
rsave = zeros(lrsave, 1);
u = zeros(npde, npts);
uinterp = zeros(npde, intpts, itype);
x = zeros(npts, 1);
isave = zeros(lisave, 1, 'int64');
cwsav = {''; ''; ''; ''; ''; ''; ''; ''; ''; ''};
lwsav = false(100, 1);
iwsav = zeros(505, 1, 'int64');
rwsav = zeros(1100, 1);
xinterp = [0.0 0.4 0.6 0.8 0.9 1.0];
acc = 1.0e3;
alpha = 1;
itrace = int64(0);
itask = int64(1);
m = int64(1);
niter = [5, 28];
tsav = zeros(niter(2), 1);
usav = zeros(2, niter(2), npts);
isav = 0;
for icalc = 1:2
piby2 = pi/2;
hx = piby2/(npts1);
x = sin(0:hx:piby2);
ts = 0;
tout = 1e5;
[u] = uinit(x, npts);
ind = int64(0);
isav = 0;
for iter = 1:niter(icalc)
%Set the endpoint.
if icalc == 1
tout = 10.0*tout;
else
if iter < 10
tout = 2*tout;
else
if iter == 10
tout = 0.01;
else
if iter < 20
tout = tout + 0.01;
else
tout = tout + 0.1;
end
end
end
end
[ts, u, rsave, isave, ind, user, cwsav, lwsav, iwsav, rwsav, ifail] = ...
d03pc(...
m, ts, tout, @pdedef, @bndary, u, x, acc, rsave, isave, itask, ...
itrace, ind, cwsav, lwsav, iwsav, rwsav);
if icalc == 1
if iter == 1
fprintf([' accuracy requirement = %12.5e\n', ...
' parameter alpha = %12.3e\n'], acc, alpha);
fprintf(' t / x ');
fprintf('%8.4f', xinterp(1:intpts));
fprintf('\n\n');
end
[uinterp, ifail] = d03pz( ...
m, u, x, xinterp, itype);
fprintf('%7.4f u(1)', tout);
fprintf('%8.4f', uinterp(1,1:intpts,1));
fprintf('\n%13s','u(2)');
fprintf('%8.4f', uinterp(2,1:intpts,1));
fprintf('\n\n');
else
isav = isav+1;
tsav(isav) = ts;
usav(1:2,isav,1:npts) = u(1:2,1:npts);
end
end
if icalc == 1
fprintf([' Number of integration steps in time = %6d\n', ...
' Number of function evaluations = %6d\n', ...
' Number of Jacobian evaluations = %6d\n', ...
' Number of iterations = %6d\n'], ...
isave(1), isave(2), isave(3), isave(5));
else
fig1 = figure;
plot_results(x, tsav, squeeze(usav(1,:,:)), 'u_1');
fig2 = figure;
plot_results(x, tsav, squeeze(usav(2,:,:)), 'u_2');
end
end
function [p, q, r, ires, user] = pdedef(npde, t, x, u, ux, ires, user)
global alpha;
p = zeros(npde,npde);
q = zeros(npde,1);
r = zeros(npde,1);
q(1) = 4*alpha*(u(2) + x*ux(2));
r(1) = x*ux(1);
r(2) = ux(2)  u(1)*u(2);
p(2,2) = 1  x*x;
function [beta, gamma, ires, user] = bndary(npde, t, u, ux, ibnd, ires, user)
if (ibnd == 0)
beta(1) = 0;
beta(2) = 1;
gamma(1) = u(1);
gamma(2) = u(1)*u(2);
else
beta(1) = 1;
beta(2) = 0;
gamma(1) = u(1);
gamma(2) = u(2);
end
function [u] = uinit(x, npts)
global alpha;
for i = 1:npts
u(1,i) = 2*alpha*x(i);
u(2,i) = 1;
end
function plot_results(x, t, u, ident)
mesh(x, t, u);
set(gca, 'YScale', 'log');
set(gca, 'YTick', [0.00001 0.0001 0.001 0.01 0.1 1]);
set(gca, 'YMinorGrid', 'off');
set(gca, 'YMinorTick', 'off');
xlabel('x');
ylabel('t');
zlabel([ident,'(x,t)']);
title({['Solution ',ident,' of ellipticparabolic pair'], ...
'using method of lines and BDF'});
title(['Solution ',ident,' of ellipticparabolic pair']);
axis([x(1) x(end) t(1) t(end)]);
view(125, 30);
d03pc example results
accuracy requirement = 1.00000e03
parameter alpha = 1.000e+00
t / x 0.0000 0.4000 0.6000 0.8000 0.9000 1.0000
0.0001 u(1) 0.0000 0.8008 1.1988 1.5990 1.7958 1.8485
u(2) 0.9997 0.9995 0.9994 0.9988 0.9663 0.0000
0.0010 u(1) 0.0000 0.7982 1.1940 1.5841 1.7179 1.6734
u(2) 0.9969 0.9952 0.9937 0.9484 0.6385 0.0000
0.0100 u(1) 0.0000 0.7676 1.1239 1.3547 1.3635 1.2830
u(2) 0.9627 0.9495 0.8754 0.5537 0.2908 0.0000
0.1000 u(1) 0.0000 0.3908 0.5007 0.5297 0.5120 0.4744
u(2) 0.5468 0.4299 0.2995 0.1479 0.0724 0.0000
1.0000 u(1) 0.0000 0.0007 0.0008 0.0008 0.0008 0.0007
u(2) 0.0010 0.0007 0.0005 0.0002 0.0001 0.0000
Number of integration steps in time = 78
Number of function evaluations = 378
Number of Jacobian evaluations = 25
Number of iterations = 190
PDF version (NAG web site
, 64bit version, 64bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015