Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_pde_1d_parab_coll (d03pd)

## Purpose

nag_pde_1d_parab_coll (d03pd) integrates a system of linear or nonlinear parabolic partial differential equations (PDEs) in one space variable. The spatial discretization is performed using a Chebyshev ${C}^{0}$ collocation method, 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, x, rsave, isave, ind, user, cwsav, lwsav, iwsav, rwsav, ifail] = d03pd(m, ts, tout, pdedef, bndary, u, xbkpts, npoly, uinit, acc, rsave, isave, itask, itrace, ind, cwsav, lwsav, iwsav, rwsav, 'npde', npde, 'nbkpts', nbkpts, 'npts', npts, 'user', user)
[ts, u, x, rsave, isave, ind, user, cwsav, lwsav, iwsav, rwsav, ifail] = nag_pde_1d_parab_coll(m, ts, tout, pdedef, bndary, u, xbkpts, npoly, uinit, acc, rsave, isave, itask, itrace, ind, cwsav, lwsav, iwsav, rwsav, 'npde', npde, 'nbkpts', nbkpts, '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_coll (d03pd) integrates the system of parabolic equations:
 $∑j=1npdePi,j ∂Uj ∂t +Qi=x-m ∂∂x xmRi, i=1,2,…,npde, a≤x≤b,t≥t0,$ (1)
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
 $U x,t = U 1 x,t ,…, U npde x,t T ,$ (2)
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{nbkpts}}}$ are the leftmost and rightmost of a user-defined set of break-points ${x}_{1},{x}_{2},\dots ,{x}_{{\mathbf{nbkpts}}}$. 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 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}$, and must be specified in uinit.
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
 $βix,tRix,t,U,Ux=γix,t,U,Ux, i=1,2,…,npde,$ (3)
where $x=a$ or $x=b$.
The boundary conditions must be specified in bndary. Thus, 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 both the break-points and internally selected points for each element in turn, that is ${P}_{i,j}$, ${Q}_{i}$ and ${R}_{i}$ are evaluated twice at each break-point. Any discontinuities in these functions must therefore be at one or more of the break-points ${x}_{1},{x}_{2},\dots ,{x}_{{\mathbf{nbkpts}}}$; (iv) at least one of the functions ${P}_{i,j}$ must be nonzero so that there is a time derivative present in the problem; (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 the mesh points. This ODE system is obtained by approximating the PDE solution between each pair of break-points by a Chebyshev polynomial of degree npoly. The interval between each pair of break-points is treated by nag_pde_1d_parab_coll (d03pd) as an element, and on this element, a polynomial and its space and time derivatives are made to satisfy the system of PDEs at ${\mathbf{npoly}}-1$ spatial points, which are chosen internally by the code and the break-points. In the case of just one element, the break-points are the boundaries. The user-defined break-points and the internally selected points together define the mesh. The smallest value that npoly can take is one, in which case, the solution is approximated by piecewise linear polynomials between consecutive break-points and the method is similar to an ordinary finite element method.
In total there are $\left({\mathbf{nbkpts}}-1\right)×{\mathbf{npoly}}+1$ mesh points in the spatial direction, and ${\mathbf{npde}}×\left(\left({\mathbf{nbkpts}}-1\right)×{\mathbf{npoly}}+1\right)$ ODEs in the time direction; one ODE at each break-point for each PDE component and (${\mathbf{npoly}}-1$) ODEs for each PDE component between each pair of break-points. The 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 and Dew P M (1991) Algorithm 690: Chebyshev polynomial software for elliptic-parabolic systems of PDEs ACM Trans. Math. Software 17 178–206
Zaturska N B, Drazin P G and Banks W H H (1988) On the flow of a viscous fluid driven along a channel by a suction at porous walls Fluid Dynamics Research 4

## 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 m-file
pdedef must compute the values of the functions ${P}_{i,j}$, ${Q}_{i}$ and ${R}_{i}$ which define the system of PDEs. The functions may depend on $x$, $t$, $U$ and ${U}_{x}$ and must be evaluated at a set of points.
[p, q, r, ires, user] = pdedef(npde, t, x, nptl, 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}\left({\mathbf{nptl}}\right)$ – double array
Contains a set of mesh points at which ${P}_{i,j}$, ${Q}_{i}$ and ${R}_{i}$ are to be evaluated. ${\mathbf{x}}\left(1\right)$ and ${\mathbf{x}}\left({\mathbf{nptl}}\right)$ contain successive user-supplied break-points and the elements of the array will satisfy ${\mathbf{x}}\left(1\right)<{\mathbf{x}}\left(2\right)<\cdots <{\mathbf{x}}\left({\mathbf{nptl}}\right)$.
4:     $\mathrm{nptl}$int64int32nag_int scalar
The number of points at which evaluations are required (the value of ${\mathbf{npoly}}+1$).
5:     $\mathrm{u}\left({\mathbf{npde}},{\mathbf{nptl}}\right)$ – double array
${\mathbf{u}}\left(\mathit{i},\mathit{j}\right)$ contains the value of the component ${U}_{\mathit{i}}\left(x,t\right)$ where $x={\mathbf{x}}\left(\mathit{j}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{npde}}$ and $\mathit{j}=1,2,\dots ,{\mathbf{nptl}}$.
6:     $\mathrm{ux}\left({\mathbf{npde}},{\mathbf{nptl}}\right)$ – double array
${\mathbf{ux}}\left(\mathit{i},\mathit{j}\right)$ contains the value of the component $\frac{\partial {U}_{\mathit{i}}\left(x,t\right)}{\partial x}$ where $x={\mathbf{x}}\left(\mathit{j}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{npde}}$ and $\mathit{j}=1,2,\dots ,{\mathbf{nptl}}$.
7:     $\mathrm{ires}$int64int32nag_int scalar
Set to $-1\text{​ or ​}1$.
8:     $\mathrm{user}$ – Any MATLAB object
pdedef is called from nag_pde_1d_parab_coll (d03pd) with the object supplied to nag_pde_1d_parab_coll (d03pd).

Output Parameters

1:     $\mathrm{p}\left({\mathbf{npde}},{\mathbf{npde}},{\mathbf{nptl}}\right)$ – double array
${\mathbf{p}}\left(\mathit{i},\mathit{j},\mathit{k}\right)$ must be set to the value of ${P}_{\mathit{i},\mathit{j}}\left(x,t,U,{U}_{x}\right)$ where $x={\mathbf{x}}\left(\mathit{k}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{npde}}$, $\mathit{j}=1,2,\dots ,{\mathbf{npde}}$ and $\mathit{k}=1,2,\dots ,{\mathbf{nptl}}$.
2:     $\mathrm{q}\left({\mathbf{npde}},{\mathbf{nptl}}\right)$ – double array
${\mathbf{q}}\left(\mathit{i},\mathit{j}\right)$ must be set to the value of ${Q}_{\mathit{i}}\left(x,t,U,{U}_{x}\right)$ where $x={\mathbf{x}}\left(\mathit{j}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{npde}}$ and $\mathit{j}=1,2,\dots ,{\mathbf{nptl}}$.
3:     $\mathrm{r}\left({\mathbf{npde}},{\mathbf{nptl}}\right)$ – double array
${\mathbf{r}}\left(\mathit{i},\mathit{j}\right)$ must be set to the value of ${R}_{\mathit{i}}\left(x,t,U,{U}_{x}\right)$ where $x={\mathbf{x}}\left(\mathit{j}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{npde}}$ and $\mathit{j}=1,2,\dots ,{\mathbf{nptl}}$.
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_coll (d03pd) 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 m-file
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
Specifies which boundary conditions are to be evaluated.
${\mathbf{ibnd}}=0$
bndary must set up the coefficients of the left-hand boundary, $x=a$.
${\mathbf{ibnd}}\ne 0$
bndary must set up the coefficients of the right-hand 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_coll (d03pd) with the object supplied to nag_pde_1d_parab_coll (d03pd).

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_coll (d03pd) 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
If ${\mathbf{ind}}=1$ the value of u must be unchanged from the previous call.
7:     $\mathrm{xbkpts}\left({\mathbf{nbkpts}}\right)$ – double array
The values of the break-points in the space direction. ${\mathbf{xbkpts}}\left(1\right)$ must specify the left-hand boundary, $a$, and ${\mathbf{xbkpts}}\left({\mathbf{nbkpts}}\right)$ must specify the right-hand boundary, $b$.
Constraint: ${\mathbf{xbkpts}}\left(1\right)<{\mathbf{xbkpts}}\left(2\right)<\cdots <{\mathbf{xbkpts}}\left({\mathbf{nbkpts}}\right)$.
8:     $\mathrm{npoly}$int64int32nag_int scalar
The degree of the Chebyshev polynomial to be used in approximating the PDE solution between each pair of break-points.
Constraint: $1\le {\mathbf{npoly}}\le 49$.
9:     $\mathrm{uinit}$ – function handle or string containing name of m-file
uinit must compute the initial values of the PDE components ${U}_{\mathit{i}}\left({x}_{\mathit{j}},{t}_{0}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{npde}}$ and $\mathit{j}=1,2,\dots ,{\mathbf{npts}}$.
[u, user] = uinit(npde, npts, x, user)

Input Parameters

1:     $\mathrm{npde}$int64int32nag_int scalar
The number of PDEs in the system.
2:     $\mathrm{npts}$int64int32nag_int scalar
The number of mesh points in the interval $\left[a,b\right]$.
3:     $\mathrm{x}\left({\mathbf{npts}}\right)$ – double array
${\mathbf{x}}\left(\mathit{j}\right)$, contains the values of the $\mathit{j}$th mesh point, for $\mathit{j}=1,2,\dots ,{\mathbf{npts}}$.
4:     $\mathrm{user}$ – Any MATLAB object
uinit is called from nag_pde_1d_parab_coll (d03pd) with the object supplied to nag_pde_1d_parab_coll (d03pd).

Output Parameters

1:     $\mathrm{u}\left({\mathbf{npde}},{\mathbf{npts}}\right)$ – double array
${\mathbf{u}}\left(\mathit{i},\mathit{j}\right)$ must be set to the initial value ${U}_{\mathit{i}}\left({x}_{\mathit{j}},{t}_{0}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{npde}}$ and $\mathit{j}=1,2,\dots ,{\mathbf{npts}}$.
2:     $\mathrm{user}$ – Any MATLAB object
10:   $\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:
 $Ei,j=acc×1.0+uij.$
Constraint: ${\mathbf{acc}}>0.0$.
11:   $\mathrm{rsave}\left(\mathit{lrsave}\right)$ – double array
lrsave, the dimension of the array, must satisfy the constraint $\mathit{lrsave}\ge 11×{\mathbf{npde}}×{\mathbf{npts}}+50+\mathit{nwkres}+\mathit{lenode}$.
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.
12:   $\mathrm{isave}\left(\mathit{lisave}\right)$int64int32nag_int array
lisave, the dimension of the array, must satisfy the constraint $\mathit{lisave}\ge {\mathbf{npde}}×{\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 back-substitution using the $LU$ decomposition of the Jacobian matrix.
13:   $\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$.
14:   $\mathrm{itrace}$int64int32nag_int scalar
The level of trace information required from nag_pde_1d_parab_coll (d03pd) 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 Sub-chapter D02M–N.
15:   $\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_coll (d03pd).
Constraint: ${\mathbf{ind}}=0$ or $1$.
16:   $\mathrm{cwsav}\left(10\right)$ – cell array of strings
17:   $\mathrm{lwsav}\left(100\right)$ – logical array
18:   $\mathrm{iwsav}\left(505\right)$int64int32nag_int array
19:   $\mathrm{rwsav}\left(1100\right)$ – double array

### 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{nbkpts}$int64int32nag_int scalar
Default: the dimension of the array xbkpts.
The number of break-points in the interval $\left[a,b\right]$.
Constraint: ${\mathbf{nbkpts}}\ge 2$.
3:     $\mathrm{npts}$int64int32nag_int scalar
Default: the second dimension of the array u.
The number of mesh points in the interval $\left[a,b\right]$.
Constraint: ${\mathbf{npts}}=\left({\mathbf{nbkpts}}-1\right)×{\mathbf{npoly}}+1$.
4:     $\mathrm{user}$ – Any MATLAB object
user is not used by nag_pde_1d_parab_coll (d03pd), but is passed to pdedef, bndary and uinit. Note that for large objects it may be more efficient to use a global variable which is accessible from the m-files 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(i,j\right)$ will contain the computed solution at $t={\mathbf{ts}}$.
3:     $\mathrm{x}\left({\mathbf{npts}}\right)$ – double array
The mesh points chosen by nag_pde_1d_parab_coll (d03pd) in the spatial direction. The values of x will satisfy ${\mathbf{x}}\left(1\right)<{\mathbf{x}}\left(2\right)<\cdots <{\mathbf{x}}\left({\mathbf{npts}}\right)$.
4:     $\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.
5:     $\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 back-substitution using the $LU$ decomposition of the Jacobian matrix.
6:     $\mathrm{ind}$int64int32nag_int scalar
${\mathbf{ind}}=1$.
7:     $\mathrm{user}$ – Any MATLAB object
8:     $\mathrm{cwsav}\left(10\right)$ – cell array of strings
9:     $\mathrm{lwsav}\left(100\right)$ – logical array
10:   $\mathrm{iwsav}\left(505\right)$int64int32nag_int array
11:   $\mathrm{rwsav}\left(1100\right)$ – double array
12:   $\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{xbkpts}}\left(1\right)<0.0$, or ${\mathbf{npde}}<1$, or ${\mathbf{nbkpts}}<2$, or ${\mathbf{npoly}}<1$ or ${\mathbf{npoly}}>49$, or ${\mathbf{npts}}\ne \left({\mathbf{nbkpts}}-1\right)×{\mathbf{npoly}}+1$, or ${\mathbf{acc}}\le 0.0$, or ${\mathbf{ind}}\ne 0$ or $1$, or break-points ${\mathbf{xbkpts}}\left(i\right)$ are not ordered, 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$
${\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_coll (d03pd) controls the accuracy of the integration in the time direction but not the accuracy of the approximation in space. The spatial accuracy depends on the degree of the polynomial approximation npoly, and on both the number of break-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.

nag_pde_1d_parab_coll (d03pd) is designed to solve parabolic systems (possibly including elliptic equations) with second-order derivatives in space. The argument specification allows you to include equations with only first-order 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.
The time taken depends on the complexity of the parabolic system and on the accuracy requested.

## Example

The problem consists of a fourth-order PDE which can be written as a pair of second-order elliptic-parabolic PDEs for ${U}_{1}\left(x,t\right)$ and ${U}_{2}\left(x,t\right)$,
 $0= ∂2U1 ∂x2 -U2$ (4)
 $∂U2 ∂t = ∂2U2 ∂x2 +U2 ∂U1 ∂x -U1 ∂U2 ∂x$ (5)
where $-1\le x\le 1$ and $t\ge 0$. The boundary conditions are given by
 $∂U1 ∂x =0 and U1=1 at ​x=-1, and ∂U1 ∂x =0 and U1=-1 at ​x=1.$
The initial conditions at $t=0$ are given by
 $U1=-sin⁡πx2 and U2=π24sin⁡πx2.$
The absence of boundary conditions for ${U}_{2}\left(x,t\right)$ does not pose any difficulties provided that the derivative flux boundary conditions are assigned to the first PDE (4) which has the correct flux, $\frac{\partial {U}_{1}}{\partial x}$. The conditions on ${U}_{1}\left(x,t\right)$ at the boundaries are assigned to the second PDE by setting ${\beta }_{2}=0.0$ in equation (3) and placing the Dirichlet boundary conditions on ${U}_{1}\left(x,t\right)$ in the function ${\gamma }_{2}$.
```function d03pd_example

fprintf('d03pd example results\n\n');

% Solution of an elliptic-parabolic pair of PDEs
% (derived from a fourth-order PDE).

% Set values for problem parameters.
npde = 2;

% Number of points on interpolated mesh, number of break points.
intpts = 6;
nbkpts = 10;

% Order of Chebyshev polynomial.
npoly = int64(3);

npts   = (nbkpts-1)*npoly + 1;
lisave = npde*npts + 24;

% Define some arrays.
rsave   = zeros(4000, 1);
u       = zeros(npde, npts);
isave   = zeros(lisave, 1, 'int64');
lwsav   = false(100, 1);
iwsav   = zeros(505, 1, 'int64');
rwsav   = zeros(1100, 1);
cwsav   = {''; ''; ''; ''; ''; ''; ''; ''; ''; ''};
% Set up the points on the interpolation grid.
xinterp = [-1:0.4:1];

% Number of output points in time.
niter  = 20;

% Prepare to store plotting results.
tsav   = zeros(niter, 1);
usav   = zeros(2, niter, npts);
isav   = 0;

% Set the break points.
hx     = 2/(nbkpts-1);
xbkpts = [-1:hx:1];

% Set initial conditions.
m      = int64(0);
ts     = 0.0;
tout   = 0.1e-4;
acc    = 1.0e-4;
itrace = int64(0);
ind0   = int64(0);

alpha  = -log(tout)/(niter-1);

% Output algorithmic details and interpolation points.
fprintf('polynomial degree = %4d    no. of elements = %4d\n', npoly, nbkpts-1);
fprintf('accuracy requirement = %10.3e    number of points = %5d', acc, npts);
fprintf('\n\n t / x       ');
fprintf('%8.4f', xinterp);
fprintf('\n\n');

% Loop over exponentially increasing endpoints of integration 0.0001 --> 1.
% Set itask = 1: normal computation of output values at t = tout.
for iter = 1:niter

tout = exp(alpha*(iter - niter));

% (re)start integration in time: ind0=0.
[ts, u, x, rsave, isave, ind, user, cwsav, lwsav, iwsav, rwsav, ifail] = ...
d03pd( ...
m, ts, tout, @pdedef, ...
@bndary, u, xbkpts, npoly, @uinit, ...
acc, rsave, isave, itask, itrace, ind0, ...
cwsav, lwsav, iwsav, rwsav);

% Interpolation onto coarser grid for display
itype  = int64(1);
[uinterp, rsave, ifail] = d03py( ...
u, xbkpts, npoly, xinterp, itype, rsave);

% Output interpolated results for this time step.
fprintf('%7.4f  u(1)', ts);
fprintf('%8.4f', uinterp(1,:,1));
fprintf('\n         u(2)');
fprintf('%8.4f', uinterp(2,:,1));
fprintf('\n\n');

% Save this timestep for plotting.
isav = isav+1;
tsav(isav) = ts;
usav(1:2,isav,1:npts) = u(1:2,1:npts);
end

% Output some statistics.
fprintf(' Number of integration steps in time = %6d\n', isave(1));
fprintf(' Number of function evaluations      = %6d\n', isave(2));
fprintf(' Number of Jacobian evaluations      = %6d\n', isave(3));
fprintf(' Number of iterations                = %6d\n', isave(5));

% Plot results.
fig1 = figure;
plot_results(x, tsav, squeeze(usav(1,:,:)), 'u_1');
fig2 = figure;
plot_results(x, tsav, squeeze(usav(2,:,:)), 'u_2');

function [p, q, r, ires, user] = pdedef(npde, t, x, nptl, u, ux, ires, user)
p = zeros(npde, npde, nptl);
q = zeros(npde, nptl);
r = zeros(npde, nptl);

for i = 1:double(nptl)
q(1,i) = u(2,i);
q(2,i) = u(1,i)*ux(2,i) - ux(1,i)*u(2,i);
r(1,i) = ux(1,i);
r(2,i) = ux(2,i);
p(2,2,i) = 1;
end;

function [beta, gamma, ires, user] = bndary(npde, t, u, ux, ibnd, ires, user)
beta  = zeros(npde, 1);
gamma = zeros(npde, 1);

beta(1)  = 1;
beta(2)  = 0;
gamma(1) = 0;
if (ibnd == 0)
gamma(2) = u(1) - 1;
else
gamma(2) = u(1) + 1;
end

function [u, user] = uinit(npde, npts, x, user)
u = zeros(npde, npts);

piby2 = pi/2;
u(1,:) = -sin(piby2*x);
u(2,:) = -piby2*piby2*u(1,:);

function plot_results(x, t, u, ident)
% Plot array as a mesh.
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');

% Label the axes, and set the title.
xlabel('x');
ylabel('t');
zlabel([ident,'(x,t)']);
title({['Solution ',ident,' of elliptic-parabolic pair'], ...
'using Chebyshev Collocation and BDF'});

% Set the axes limits tight to the x and y range.
axis([x(1) x(end) t(1) t(end)]);

% Set the view to something nice (determined empirically).
view(-165, 44);
```
```d03pd example results

polynomial degree =    3    no. of elements =    9
accuracy requirement =  1.000e-04    number of points =    28

t / x        -1.0000 -0.6000 -0.2000  0.2000  0.6000  1.0000

0.0000  u(1)  1.0000  0.8090  0.3090 -0.3090 -0.8090 -1.0000
u(2) -2.4690 -1.9961 -0.7624  0.7624  1.9961  2.4690

0.0000  u(1)  1.0000  0.8090  0.3090 -0.3090 -0.8090 -1.0000
u(2) -2.4687 -1.9961 -0.7624  0.7624  1.9961  2.4687

0.0000  u(1)  1.0000  0.8090  0.3090 -0.3090 -0.8090 -1.0000
u(2) -2.4700 -1.9961 -0.7624  0.7624  1.9961  2.4700

0.0001  u(1)  1.0000  0.8090  0.3090 -0.3090 -0.8090 -1.0000
u(2) -2.4724 -1.9960 -0.7624  0.7624  1.9960  2.4724

0.0001  u(1)  1.0000  0.8090  0.3090 -0.3090 -0.8090 -1.0000
u(2) -2.4767 -1.9959 -0.7624  0.7624  1.9959  2.4767

0.0002  u(1)  1.0000  0.8090  0.3090 -0.3090 -0.8090 -1.0000
u(2) -2.4840 -1.9957 -0.7623  0.7623  1.9957  2.4840

0.0004  u(1)  1.0000  0.8089  0.3090 -0.3090 -0.8089 -1.0000
u(2) -2.4960 -1.9953 -0.7621  0.7621  1.9953  2.4960

0.0007  u(1)  1.0000  0.8089  0.3089 -0.3089 -0.8089 -1.0000
u(2) -2.5142 -1.9946 -0.7619  0.7619  1.9946  2.5142

0.0013  u(1)  1.0000  0.8087  0.3089 -0.3089 -0.8087 -1.0000
u(2) -2.5374 -1.9933 -0.7614  0.7614  1.9933  2.5374

0.0023  u(1)  1.0000  0.8085  0.3087 -0.3087 -0.8085 -1.0000
u(2) -2.5611 -1.9910 -0.7605  0.7605  1.9910  2.5611

0.0043  u(1)  1.0000  0.8081  0.3085 -0.3085 -0.8081 -1.0000
u(2) -2.5869 -1.9866 -0.7588  0.7588  1.9866  2.5869

0.0078  u(1)  1.0000  0.8074  0.3081 -0.3081 -0.8074 -1.0000
u(2) -2.6183 -1.9787 -0.7558  0.7558  1.9787  2.6183

0.0144  u(1)  1.0000  0.8063  0.3075 -0.3075 -0.8063 -1.0000
u(2) -2.6604 -1.9643 -0.7503  0.7503  1.9643  2.6604

0.0264  u(1)  1.0000  0.8045  0.3064 -0.3064 -0.8045 -1.0000
u(2) -2.7128 -1.9394 -0.7402  0.7402  1.9394  2.7128

0.0483  u(1)  1.0000  0.8020  0.3046 -0.3046 -0.8020 -1.0000
u(2) -2.7723 -1.9042 -0.7222  0.7222  1.9042  2.7723

0.0886  u(1)  1.0000  0.7990  0.3022 -0.3022 -0.7990 -1.0000
u(2) -2.8331 -1.8684 -0.6915  0.6915  1.8684  2.8331

0.1624  u(1)  1.0000  0.7962  0.2996 -0.2996 -0.7962 -1.0000
u(2) -2.8840 -1.8423 -0.6512  0.6512  1.8423  2.8840

0.2976  u(1)  1.0000  0.7944  0.2978 -0.2978 -0.7944 -1.0000
u(2) -2.9140 -1.8287 -0.6218  0.6218  1.8287  2.9140

0.5456  u(1)  1.0000  0.7939  0.2973 -0.2973 -0.7939 -1.0000
u(2) -2.9225 -1.8250 -0.6129  0.6129  1.8250  2.9225

1.0000  u(1)  1.0000  0.7939  0.2972 -0.2972 -0.7939 -1.0000
u(2) -2.9233 -1.8247 -0.6120  0.6120  1.8247  2.9233

Number of integration steps in time =     38
Number of function evaluations      =    237
Number of Jacobian evaluations      =      9
Number of iterations                =     89
```