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

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

# 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:
Mark 22: lrsave, lisave have been removed from the interface
.

## Description

nag_pde_1d_parab_fd (d03pc) integrates the system of parabolic equations:
 npde ∑ Pi,j( ∂ Uj)/( ∂ t) + Qi = x − m( ∂ )/( ∂ x)(xmRi),  i = 1,2, … ,npde,  a ≤ x ≤ b,  t ≥ t0, j = 1
$∑j=1npdePi,j ∂Uj ∂t +Qi=x-m ∂∂x (xmRi), i=1,2,…,npde, a≤x≤b, t≥t0,$
(1)
where Pi,j${P}_{i,j}$, Qi${Q}_{i}$ and Ri${R}_{i}$ depend on x$x$, t$t$, U$U$, Ux${U}_{x}$ and the vector U$U$ is the set of solution values
 U (x,t) = [ U1 (x,t) , … , Unpde (x,t) ]T , $U (x,t) = [ U 1 (x,t) ,…, U npde (x,t) ] T ,$ (2)
and the vector Ux${U}_{x}$ is its partial derivative with respect to x$x$. Note that Pi,j${P}_{i,j}$, Qi${Q}_{i}$ and Ri${R}_{i}$ must not depend on (U)/(t) $\frac{\partial U}{\partial t}$.
The integration in time is from t0${t}_{0}$ to tout${t}_{\mathrm{out}}$, over the space interval axb$a\le x\le b$, where a = x1$a={x}_{1}$ and b = xnpts$b={x}_{{\mathbf{npts}}}$ are the leftmost and rightmost points of a user-defined mesh x1,x2,,xnpts${x}_{1},{x}_{2},\dots ,{x}_{{\mathbf{npts}}}$. The coordinate system in space is defined by the value of m$m$; m = 0$m=0$ for Cartesian coordinates, m = 1$m=1$ for cylindrical polar coordinates and m = 2$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 Pi,j${P}_{i,j}$, Qi${Q}_{i}$ and Ri${R}_{i}$ which must be specified in pdedef.
The initial values of the functions U(x,t)$U\left(x,t\right)$ must be given at t = t0$t={t}_{0}$. The functions Ri${R}_{i}$, for i = 1,2,,npde$\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
 βi(x,t)Ri(x,t,U,Ux) = γi(x,t,U,Ux),  i = 1,2, … ,npde, $βi(x,t)Ri(x,t,U,Ux)=γi(x,t,U,Ux), i=1,2,…,npde,$ (3)
where x = a$x=a$ or x = b$x=b$.
The boundary conditions must be specified in bndary.
The problem is subject to the following restrictions:
 (i) t0 < tout${t}_{0}<{t}_{\mathrm{out}}$, so that integration is in the forward direction; (ii) Pi,j${P}_{i,j}$, Qi${Q}_{i}$ and the flux Ri${R}_{i}$ must not depend on any time derivatives; (iii) the evaluation of the functions Pi,j${P}_{i,j}$, Qi${Q}_{i}$ and Ri${R}_{i}$ is done at the mid-points of the mesh intervals by calling the pdedef for each mid-point in turn. Any discontinuities in these functions must therefore be at one or more of the mesh points x1,x2, … ,xnpts${x}_{1},{x}_{2},\dots ,{x}_{{\mathbf{npts}}}$; (iv) at least one of the functions Pi,j${P}_{i,j}$ must be nonzero so that there is a time derivative present in the problem; and (v) if m > 0$m>0$ and x1 = 0.0${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$x=0.0$ or by specifying a zero flux there, that is βi = 1.0${\beta }_{i}=1.0$ and γi = 0.0${\gamma }_{i}=0.0$. See also Section [Further Comments].
The parabolic equations are approximated by a system of ODEs in time for the values of Ui${U}_{i}$ at mesh points. For simple problems in Cartesian coordinates, this system is obtained by replacing the space derivatives by the usual central, three-point finite difference formula. However, for polar and spherical problems, or problems with nonlinear coefficients, the space derivatives are replaced by a modified three-point formula which maintains second-order accuracy. In total there are ${\mathbf{npde}}×{\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 time-dependent problems using the method of lines and differential-algebraic 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:     m – int64int32nag_int scalar
The coordinate system used:
m = 0${\mathbf{m}}=0$
Indicates Cartesian coordinates.
m = 1${\mathbf{m}}=1$
Indicates cylindrical polar coordinates.
m = 2${\mathbf{m}}=2$
Indicates spherical polar coordinates.
Constraint: m = 0${\mathbf{m}}=0$, 1$1$ or 2$2$.
2:     ts – double scalar
The initial value of the independent variable t$t$.
Constraint: ${\mathbf{ts}}<{\mathbf{tout}}$.
3:     tout – double scalar
The final value of t$t$ to which the integration is to be carried out.
4:     pdedef – function handle or string containing name of m-file
pdedef must compute the functions Pi,j${P}_{i,j}$, Qi${Q}_{i}$ and Ri${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:     npde – int64int32nag_int scalar
The number of PDEs in the system.
2:     t – double scalar
The current value of the independent variable t$t$.
3:     x – double scalar
The current value of the space variable x$x$.
4:     u(npde) – double array
u(i)${\mathbf{u}}\left(\mathit{i}\right)$ contains the value of the component Ui(x,t)${U}_{\mathit{i}}\left(x,t\right)$, for i = 1,2,,npde$\mathit{i}=1,2,\dots ,{\mathbf{npde}}$.
5:     ux(npde) – double array
ux(i)${\mathbf{ux}}\left(\mathit{i}\right)$ contains the value of the component (Ui(x,t))/(x) $\frac{\partial {U}_{\mathit{i}}\left(x,t\right)}{\partial x}$, for i = 1,2,,npde$\mathit{i}=1,2,\dots ,{\mathbf{npde}}$.
6:     ires – int64int32nag_int scalar
Set to 1​ or ​1$-1\text{​ or ​}1$.
7:     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:     p(npde,npde) – double array
p(i,j)${\mathbf{p}}\left(\mathit{i},\mathit{j}\right)$ must be set to the value of Pi,j(x,t,U,Ux)${P}_{\mathit{i},\mathit{j}}\left(x,t,U,{U}_{x}\right)$, for i = 1,2,,npde$\mathit{i}=1,2,\dots ,{\mathbf{npde}}$ and j = 1,2,,npde$\mathit{j}=1,2,\dots ,{\mathbf{npde}}$.
2:     q(npde) – double array
q(i)${\mathbf{q}}\left(\mathit{i}\right)$ must be set to the value of Qi(x,t,U,Ux)${Q}_{\mathit{i}}\left(x,t,U,{U}_{x}\right)$, for i = 1,2,,npde$\mathit{i}=1,2,\dots ,{\mathbf{npde}}$.
3:     r(npde) – double array
r(i)${\mathbf{r}}\left(\mathit{i}\right)$ must be set to the value of Ri(x,t,U,Ux)${R}_{\mathit{i}}\left(x,t,U,{U}_{x}\right)$, for i = 1,2,,npde$\mathit{i}=1,2,\dots ,{\mathbf{npde}}$.
4:     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:
ires = 2${\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}}$.
ires = 3${\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 ires = 3${\mathbf{ires}}=3$ when a physically meaningless input or output value has been generated. If you consecutively set ires = 3${\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:     user – Any MATLAB object
5:     bndary – function handle or string containing name of m-file
bndary must compute the functions βi${\beta }_{i}$ and γi${\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:     npde – int64int32nag_int scalar
The number of PDEs in the system.
2:     t – double scalar
The current value of the independent variable t$t$.
3:     u(npde) – double array
u(i)${\mathbf{u}}\left(\mathit{i}\right)$ contains the value of the component Ui(x,t)${U}_{\mathit{i}}\left(x,t\right)$ at the boundary specified by ibnd, for i = 1,2,,npde$\mathit{i}=1,2,\dots ,{\mathbf{npde}}$.
4:     ux(npde) – double array
ux(i)${\mathbf{ux}}\left(\mathit{i}\right)$ contains the value of the component (Ui(x,t))/(x) $\frac{\partial {U}_{\mathit{i}}\left(x,t\right)}{\partial x}$ at the boundary specified by ibnd, for i = 1,2,,npde$\mathit{i}=1,2,\dots ,{\mathbf{npde}}$.
5:     ibnd – int64int32nag_int scalar
Determines the position of the boundary conditions.
ibnd = 0${\mathbf{ibnd}}=0$
bndary must set up the coefficients of the left-hand boundary, x = a$x=a$.
ibnd0${\mathbf{ibnd}}\ne 0$
Indicates that bndary must set up the coefficients of the right-hand boundary, x = b$x=b$.
6:     ires – int64int32nag_int scalar
Set to 1​ or ​1$-1\text{​ or ​}1$.
7:     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:     beta(npde) – double array
beta(i)${\mathbf{beta}}\left(\mathit{i}\right)$ must be set to the value of βi(x,t)${\beta }_{\mathit{i}}\left(x,t\right)$ at the boundary specified by ibnd, for i = 1,2,,npde$\mathit{i}=1,2,\dots ,{\mathbf{npde}}$.
2:     gamma(npde) – double array
gamma(i)${\mathbf{gamma}}\left(\mathit{i}\right)$ must be set to the value of γi(x,t,U,Ux)${\gamma }_{\mathit{i}}\left(x,t,U,{U}_{x}\right)$ at the boundary specified by ibnd, for i = 1,2,,npde$\mathit{i}=1,2,\dots ,{\mathbf{npde}}$.
3:     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:
ires = 2${\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}}$.
ires = 3${\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 ires = 3${\mathbf{ires}}=3$ when a physically meaningless input or output value has been generated. If you consecutively set ires = 3${\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:     user – Any MATLAB object
6:     u(npde,npts) – double array
npde, the first dimension of the array, must satisfy the constraint npde1${\mathbf{npde}}\ge 1$.
The initial values of U(x,t)$U\left(x,t\right)$ at t = ts$t={\mathbf{ts}}$ and the mesh points x(j)${\mathbf{x}}\left(\mathit{j}\right)$, for j = 1,2,,npts$\mathit{j}=1,2,\dots ,{\mathbf{npts}}$.
7:     x(npts) – double array
npts, the dimension of the array, must satisfy the constraint npts3${\mathbf{npts}}\ge 3$.
The mesh points in the spatial direction. x(1)${\mathbf{x}}\left(1\right)$ must specify the left-hand boundary, a$a$, and x(npts)${\mathbf{x}}\left({\mathbf{npts}}\right)$ must specify the right-hand boundary, b$b$.
Constraint: x(1) < x(2) < < x(npts)${\mathbf{x}}\left(1\right)<{\mathbf{x}}\left(2\right)<\cdots <{\mathbf{x}}\left({\mathbf{npts}}\right)$.
8:     acc – double scalar
A positive quantity for controlling the local error estimate in the time integration. If E(i,j)$E\left(i,j\right)$ is the estimated error for Ui${U}_{i}$ at the j$j$th mesh point, the error test is:
 |E(i,j)| = acc × (1.0 + |u(i,j)|). $|E(i,j)|=acc×(1.0+|uij|).$
Constraint: acc > 0.0${\mathbf{acc}}>0.0$.
9:     rsave(lrsave) – double array
lrsave, the dimension of the array, must satisfy the constraint lrsave(6 × npde + 10) × npde × npts + (3 × npde + 21) × npde +  7 × npts + 54$\mathit{lrsave}\ge \left(6×{\mathbf{npde}}+10\right)×{\mathbf{npde}}×{\mathbf{npts}}+\left(3×{\mathbf{npde}}+21\right)×{\mathbf{npde}}+\phantom{\rule{0ex}{0ex}}7×{\mathbf{npts}}+54$.
If ind = 0${\mathbf{ind}}=0$, rsave need not be set on entry.
If ind = 1${\mathbf{ind}}=1$, rsave must be unchanged from the previous call to the function because it contains required information about the iteration.
10:   isave(lisave) – int64int32nag_int array
lisave, the dimension of the array, must satisfy the constraint lisavenpde × npts + 24$\mathit{lisave}\ge {\mathbf{npde}}×{\mathbf{npts}}+24$.
If ind = 0${\mathbf{ind}}=0$, isave need not be set on entry.
If ind = 1${\mathbf{ind}}=1$, isave must be unchanged from the previous call to the function because it contains required information about the iteration. In particular:
isave(1)${\mathbf{isave}}\left(1\right)$
Contains the number of steps taken in time.
isave(2)${\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.
isave(3)${\mathbf{isave}}\left(3\right)$
Contains the number of Jacobian evaluations performed by the time integrator.
isave(4)${\mathbf{isave}}\left(4\right)$
Contains the order of the last backward differentiation formula method used.
isave(5)${\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$LU$ decomposition of the Jacobian matrix.
11:   itask – int64int32nag_int scalar
Specifies the task to be performed by the ODE integrator.
itask = 1${\mathbf{itask}}=1$
Normal computation of output values u at t = tout$t={\mathbf{tout}}$.
itask = 2${\mathbf{itask}}=2$
One step and return.
itask = 3${\mathbf{itask}}=3$
Stop at first internal integration point at or beyond t = tout$t={\mathbf{tout}}$.
Constraint: itask = 1${\mathbf{itask}}=1$, 2$2$ or 3$3$.
12:   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$-1$, 0$0$, 1$1$, 2$2$ or 3$3$.
itrace = 1${\mathbf{itrace}}=-1$
No output is generated.
itrace = 0${\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)).
itrace > 0${\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 itrace < 1${\mathbf{itrace}}<-1$, then 1$-1$ is assumed and similarly if itrace > 3${\mathbf{itrace}}>3$, then 3$3$ is assumed.
The advisory messages are given in greater detail as itrace increases. You are advised to set itrace = 0${\mathbf{itrace}}=0$, unless you are experienced with sub-chapter D02M–N.
13:   ind – int64int32nag_int scalar
Indicates whether this is a continuation call or a new integration.
ind = 0${\mathbf{ind}}=0$
Starts or restarts the integration in time.
ind = 1${\mathbf{ind}}=1$
Continues the integration after an earlier exit from the function. In this case, only the parameters tout and ifail should be reset between calls to nag_pde_1d_parab_fd (d03pc).
Constraint: ind = 0${\mathbf{ind}}=0$ or 1$1$.
14:   cwsav(10$10$) – cell array of strings
If ind = 0${\mathbf{ind}}=0$, cwsav need not be set on entry.
If ind = 1${\mathbf{ind}}=1$, cwsav must be unchanged from the previous call to the function.
15:   lwsav(100$100$) – logical array
If ind = 0${\mathbf{ind}}=0$, lwsav need not be set on entry.
If ind = 1${\mathbf{ind}}=1$, lwsav must be unchanged from the previous call to the function.
16:   iwsav(505$505$) – int64int32nag_int array
If ind = 0${\mathbf{ind}}=0$, iwsav need not be set on entry.
If ind = 1${\mathbf{ind}}=1$, iwsav must be unchanged from the previous call to the function.
17:   rwsav(1100$1100$) – double array
If ind = 0${\mathbf{ind}}=0$, rwsav need not be set on entry.
If ind = 1${\mathbf{ind}}=1$, rwsav must be unchanged from the previous call to the function.

### Optional Input Parameters

1:     npde – int64int32nag_int scalar
Default: The first dimension of the array u.
The number of PDEs in the system to be solved.
Constraint: npde1${\mathbf{npde}}\ge 1$.
2:     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 [a,b]$\left[a,b\right]$.
Constraint: npts3${\mathbf{npts}}\ge 3$.
3:     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 m-files than to use user.

### Input Parameters Omitted from the MATLAB Interface

lrsave lisave iuser ruser

### Output Parameters

1:     ts – double scalar
The value of t$t$ corresponding to the solution values in u. Normally ${\mathbf{ts}}={\mathbf{tout}}$.
2:     u(npde,npts) – double array
u(i,j)${\mathbf{u}}\left(\mathit{i},\mathit{j}\right)$ will contain the computed solution at t = ts$t={\mathbf{ts}}$.
3:     rsave(lrsave) – double array
If ind = 1${\mathbf{ind}}=1$, rsave must be unchanged from the previous call to the function because it contains required information about the iteration.
4:     isave(lisave) – int64int32nag_int array
If ind = 1${\mathbf{ind}}=1$, isave must be unchanged from the previous call to the function because it contains required information about the iteration. In particular:
isave(1)${\mathbf{isave}}\left(1\right)$
Contains the number of steps taken in time.
isave(2)${\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.
isave(3)${\mathbf{isave}}\left(3\right)$
Contains the number of Jacobian evaluations performed by the time integrator.
isave(4)${\mathbf{isave}}\left(4\right)$
Contains the order of the last backward differentiation formula method used.
isave(5)${\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$LU$ decomposition of the Jacobian matrix.
5:     ind – int64int32nag_int scalar
ind = 1${\mathbf{ind}}=1$.
6:     user – Any MATLAB object
7:     cwsav(10$10$) – cell array of strings
If ind = 1${\mathbf{ind}}=1$, cwsav must be unchanged from the previous call to the function.
8:     lwsav(100$100$) – logical array
If ind = 1${\mathbf{ind}}=1$, lwsav must be unchanged from the previous call to the function.
9:     iwsav(505$505$) – int64int32nag_int array
If ind = 1${\mathbf{ind}}=1$, iwsav must be unchanged from the previous call to the function.
10:   rwsav(1100$1100$) – double array
If ind = 1${\mathbf{ind}}=1$, rwsav must be unchanged from the previous call to the function.
11:   ifail – int64int32nag_int scalar
${\mathrm{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.

ifail = 1${\mathbf{ifail}}=1$
 On entry, ${\mathbf{tout}}\le {\mathbf{ts}}$, or ${\mathbf{tout}}-{\mathbf{ts}}$ is too small, or itask ≠ 1${\mathbf{itask}}\ne 1$, 2$2$ or 3$3$, or m ≠ 0${\mathbf{m}}\ne 0$, 1$1$ or 2$2$, or m > 0${\mathbf{m}}>0$ and x(1) < 0.0${\mathbf{x}}\left(1\right)<0.0$, or the mesh points ​x(i) $\text{the mesh points ​}{\mathbf{x}}\left(i\right)$ are not ordered, or npts < 3${\mathbf{npts}}<3$, or npde < 1${\mathbf{npde}}<1$, or acc ≤ 0.0${\mathbf{acc}}\le 0.0$, or ind ≠ 0${\mathbf{ind}}\ne 0$ or 1$1$, or lrsave is too small, or lisave is too small.
W ifail = 2${\mathbf{ifail}}=2$
The underlying ODE solver cannot make any further progress across the integration range from the current point t = ts$t={\mathbf{ts}}$ with the supplied value of acc. The components of u contain the computed values at the current point t = ts$t={\mathbf{ts}}$.
W ifail = 3${\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 = ts$t={\mathbf{ts}}$.
ifail = 4${\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$3$ in at least pdedef or bndary, when the residual in the underlying ODE solver was being evaluated.
ifail = 5${\mathbf{ifail}}=5$
In solving the ODE system, a singular Jacobian has been encountered. You should check your problem formulation.
W ifail = 6${\mathbf{ifail}}=6$
When evaluating the residual in solving the ODE system, ires was set to 2$2$ in at least pdedef or bndary. Integration was successful as far as t = ts$t={\mathbf{ts}}$.
ifail = 7${\mathbf{ifail}}=7$
The value of acc is so small that the function is unable to start the integration in time.
ifail = 8${\mathbf{ifail}}=8$
In one of pdedef or bndary, ires was set to an invalid value.
ifail = 9${\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 parameters and array dimensions. Setting itrace = 1${\mathbf{itrace}}=1$ may provide more information. If the problem persists, contact NAG.
W ifail = 10${\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 itask2${\mathbf{itask}}\ne 2$.)
ifail = 11${\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).
ifail = 12${\mathbf{ifail}}=12$
Not applicable.
ifail = 13${\mathbf{ifail}}=13$
Not applicable.
ifail = 14${\mathbf{ifail}}=14$
The flux function Ri${R}_{i}$ was detected as depending on time derivatives, which is not permissible.

## 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 parameter, acc.

nag_pde_1d_parab_fd (d03pc) is designed to solve parabolic systems (possibly including some elliptic equations) with second-order derivatives in space. The parameter 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. It may be advisable in such cases to reduce the whole system to first-order 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 elliptic-parabolic pair of PDEs. The problem was originally derived from a single third-order in space PDE. The elliptic equation is
 1/r( ∂ )/( ∂ r) (r2( ∂ U1)/( ∂ r)) = 4α (U2 + r( ∂ U2)/( ∂ r)) $1r ∂∂r (r2 ∂U1 ∂r )=4α (U2+r ∂U2 ∂r )$
and the parabolic equation is
 (1 − r2) ( ∂ U2)/( ∂ t) = 1/r( ∂ )/( ∂ r) (r(( ∂ U2)/( ∂ r) − U2U1)) $(1-r2) ∂U2 ∂t =1r ∂∂r (r ( ∂U2 ∂r -U2U1) )$
where (r,t)[0,1] × [0,1]$\left(r,t\right)\in \left[0,1\right]×\left[0,1\right]$. The boundary conditions are given by
 U1 = ( ∂ U2)/( ∂ r) = 0  at ​r = 0, $U1= ∂U2 ∂r =0 at ​r=0,$
and
 ( ∂ )/( ∂ r)(rU1) = 0   and   U2 = 0   at ​ r = 1. $∂∂r (rU1)= 0 and U2= 0 at ​ r=1.$
The first of these boundary conditions implies that the flux term in the second PDE, ((U2)/(r)U2U1) $\left(\frac{\partial {U}_{2}}{\partial r}-{U}_{2}{U}_{1}\right)$, is zero at r = 0$r=0$.
The initial conditions at t = 0$t=0$ are given by
 U1 = 2αr  and  U2 = 1.0,   ​r ∈ [0,1]. $U1=2αr and U2=1.0, ​r∈[0,1].$
The value α = 1$\alpha =1$ was used in the problem definition. A mesh of 20$20$ points was used with a circular mesh spacing to cluster the points towards the right-hand side of the spatial interval, r = 1$r=1$.
```function  nag_pde_1d_parab_fd_example
%  Solution of an elliptic-parabolic pair of PDEs.
global alpha;

% Set values for problem parameters.
npde = 2;

% Number of points on calculation mesh, and on interpolated mesh.
npts = 20;
intpts = 6;

itype = 1;
neqn = npde*npts;
lisave = neqn + 24;
nwk = (10 + 6*npde)*neqn;
lrsave = nwk + (21 + 3*npde)*npde + 7*npts + 54;

% Define some arrays.
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);

% Set up the points on the interpolation grid.
xinterp = [0.0 0.4 0.6 0.8 0.9 1.0];

acc = 1.0e-3;
alpha = 1.0;

itrace = 0;
m = 1; % Use cylindrical polar coordinates.

% We run through the calculation twice; once to output the interpolated
% results, and once to store the results for plotting.
niter = [5, 28];

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

fprintf('nag_pde_1d_parab_fd example program results\n\n');
for icalc = 1:2

% Set spatial mesh points.
piby2 = 0.5*pi;
hx = piby2/(npts-1.0);
x(1) = 0.0;
x(npts) = 1.0;
for i = 2:npts-1
x(i) = sin(hx*(i-1.0));
end

% Set initial conditions.
ts = 0.0;
tout = 0.1e-4;

% Set the initial values.
[u] = uinit(x, npts);

% Start the integration in time.
ind = 0;

% Counter for saved results.
isav = 0;

% Loop over endpoints for the integration.  We've set itask = 1, which
% gives normal computation of output values at t = tout.
for iter = 1:niter(icalc)

%Set the endpoint.
if icalc == 1
tout = 10.0*tout;
else
if iter < 10
tout = 2.0*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

% The first time this is called, ind is 0, which (re)starts the
% integration in time.  On exit, ind is set to 1; using this value
% on a subsequent call continues the integration.  This means that
% only tout and ifail should be reset between calls (i.e. the
% output variables must have the same names as the input
% variables - cf original MB22 example).
[ts, u, rsave, isave, ind, user, cwsav, lwsav, iwsav, rwsav, ...
ifail] = nag_pde_1d_parab_fd(int64(m), ts, tout, @pdedef, ...
@bndary, u, x, acc, rsave, isave, int64(itask), ...
int64(itrace), int64(ind), cwsav, lwsav, iwsav, rwsav);
if ifail ~= 0
% Parameters out of range, or convergence problems.
% Print message and exit.
fprintf('Warning: nag_pde_1d_parab_fd returned with ifail = %1d \n\n',ifail);
return;
end

if icalc == 1
% Output interpolation points first time through.
if iter == 1
fprintf([' accuracy requirement = %12.5e\n', ...
' parameter alpha =  %12.3e\n'], acc, alpha);
fprintf(' t / x     ');
for i = 1:intpts
fprintf('%8.4f', xinterp(i));
end
fprintf('\n\n');
end

% Call nag_pde_1d_parab_fd_interp to do interpolation of results onto
% coarser grid.
[uinterp, ifail] = nag_pde_1d_parab_fd_interp(int64(m), u, x, xinterp, ...
int64(itype));
if ifail ~= 0
% Parameters out of range, or convergence problems.
% Print message and exit.
fprintf(['Warning: nag_pde_1d_parab_fd_interp returned with ifail = ', ...
'%1d \n\n'], ifail);
return;
end

% Output interpolated results for this time step.
fprintf('%7.4f  u(1)', tout);
for i = 1:intpts
fprintf('%8.4f', uinterp(1,i,1));
end
fprintf('\n');
fprintf('     u(2)');
for i = 1:intpts
fprintf('%8.4f', uinterp(2,i,1));
end
fprintf('\n\n');
else
% Save this timestep, and this set of results.
isav = isav+1;
tsav(isav) = ts;
for ipt = 1:npts
for isol = 1:2
usav(isol,isav,ipt) = u(isol,ipt);
end
end
end
end

if icalc == 1
% Output some statistics.
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
% Plot results.
fig1 = figure('Number', 'off');
plot_results(x, tsav, squeeze(usav(1,:,:)), 'U1');
fig2 = figure('Number', 'off');
plot_results(x, tsav, squeeze(usav(2,:,:)), 'U2');
end
end

function [p, q, r, ires, user] = pdedef(npde, t, x, u, ux, ires, user)
% Evaluate Pij, Qi and Ri which define the system of PDEs.
global alpha;

p = zeros(npde,npde);
q = zeros(npde,1);
r = zeros(npde,1);
q(1) = 4.0*alpha*(u(2) + x*ux(2));
q(2) = 0.0;
r(1) = x*ux(1);
r(2) = ux(2) - u(1)*u(2);
p(1,1) = 0.0;
p(1,2) = 0.0;
p(2,1) = 0.0;
p(2,2) = 1.0 - x*x;

function [beta, gamma, ires, user] = bndary(npde, t, u, ux, ibnd, ires, user)
% Evaluate beta and gamma to define the boundary conditions.

if (ibnd == 0)
beta(1) = 0.0;
beta(2) = 1.0;
gamma(1) = u(1);
gamma(2) = -u(1)*u(2);
else
beta(1) = 1.0;
beta(2) = 0.0;
gamma(1) = -u(1);
gamma(2) = u(2);
end

function [u] = uinit(x, npts)
% Set initial values for solution.
global alpha;

for i = 1:npts
u(1,i) = 2.0*alpha*x(i);
u(2,i) = 1.0;
end

function plot_results(x, t, u, ident)
% Formatting for title and axis labels.
titleFmt = {'FontName', 'Helvetica', 'FontWeight', 'Bold', 'FontSize', 14};
labFmt = {'FontName', 'Helvetica', 'FontWeight', 'Bold', 'FontSize', 13};
set(gca, 'FontSize', 13); % for legend, axis tick labels, etc.

% 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', labFmt{:});
ylabel('t', labFmt{:});
zlabel([ident,'(x,t)'], labFmt{:});
title({['Solution ',ident,' of elliptic-parabolic pair'], ...
'using method of lines and BDF'}, titleFmt{:});
title(['Solution ',ident,' of elliptic-parabolic pair'], titleFmt{:});

% 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(-125, 30);
```
```
nag_pde_1d_parab_fd example program results

accuracy requirement =  1.00000e-03
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

```
```function  d03pc_example
%  Solution of an elliptic-parabolic pair of PDEs.
global alpha;

% Set values for problem parameters.
npde = 2;

% Number of points on calculation mesh, and on interpolated mesh.
npts = 20;
intpts = 6;

itype = 1;
neqn = npde*npts;
lisave = neqn + 24;
nwk = (10 + 6*npde)*neqn;
lrsave = nwk + (21 + 3*npde)*npde + 7*npts + 54;

% Define some arrays.
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);

% Set up the points on the interpolation grid.
xinterp = [0.0 0.4 0.6 0.8 0.9 1.0];

acc = 1.0e-3;
alpha = 1.0;

itrace = 0;
m = 1; % Use cylindrical polar coordinates.

% We run through the calculation twice; once to output the interpolated
% results, and once to store the results for plotting.
niter = [5, 28];

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

fprintf('d03pc example program results\n\n');
for icalc = 1:2

% Set spatial mesh points.
piby2 = 0.5*pi;
hx = piby2/(npts-1.0);
x(1) = 0.0;
x(npts) = 1.0;
for i = 2:npts-1
x(i) = sin(hx*(i-1.0));
end

% Set initial conditions.
ts = 0.0;
tout = 0.1e-4;

% Set the initial values.
[u] = uinit(x, npts);

% Start the integration in time.
ind = 0;

% Counter for saved results.
isav = 0;

% Loop over endpoints for the integration.  We've set itask = 1, which
% gives normal computation of output values at t = tout.
for iter = 1:niter(icalc)

%Set the endpoint.
if icalc == 1
tout = 10.0*tout;
else
if iter < 10
tout = 2.0*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

% The first time this is called, ind is 0, which (re)starts the
% integration in time.  On exit, ind is set to 1; using this value
% on a subsequent call continues the integration.  This means that
% only tout and ifail should be reset between calls (i.e. the
% output variables must have the same names as the input
% variables - cf original MB22 example).
[ts, u, rsave, isave, ind, user, cwsav, lwsav, iwsav, rwsav, ...
ifail] = d03pc(int64(m), ts, tout, @pdedef, ...
@bndary, u, x, acc, rsave, isave, int64(itask), ...
int64(itrace), int64(ind), cwsav, lwsav, iwsav, rwsav);
if ifail ~= 0
% Parameters out of range, or convergence problems.
% Print message and exit.
fprintf('Warning: d03pc returned with ifail = %1d \n\n',ifail);
return;
end

if icalc == 1
% Output interpolation points first time through.
if iter == 1
fprintf([' accuracy requirement = %12.5e\n', ...
' parameter alpha =  %12.3e\n'], acc, alpha);
fprintf(' t / x     ');
for i = 1:intpts
fprintf('%8.4f', xinterp(i));
end
fprintf('\n\n');
end

% Call d03pz to do interpolation of results onto coarser grid.
[uinterp, ifail] = d03pz(int64(m), u, x, xinterp, int64(itype));
if ifail ~= 0
% Parameters out of range, or convergence problems.
% Print message and exit.
fprintf(['Warning: d03pz returned with ifail = ', ...
'%1d \n\n'], ifail);
return;
end

% Output interpolated results for this time step.
fprintf('%7.4f  u(1)', tout);
for i = 1:intpts
fprintf('%8.4f', uinterp(1,i,1));
end
fprintf('\n');
fprintf('     u(2)');
for i = 1:intpts
fprintf('%8.4f', uinterp(2,i,1));
end
fprintf('\n\n');
else
% Save this timestep, and this set of results.
isav = isav+1;
tsav(isav) = ts;
for ipt = 1:npts
for isol = 1:2
usav(isol,isav,ipt) = u(isol,ipt);
end
end
end
end

if icalc == 1
% Output some statistics.
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
% Plot results.
fig1 = figure('Number', 'off');
plot_results(x, tsav, squeeze(usav(1,:,:)), 'U1');
fig2 = figure('Number', 'off');
plot_results(x, tsav, squeeze(usav(2,:,:)), 'U2');
end
end

function [p, q, r, ires, user] = pdedef(npde, t, x, u, ux, ires, user)
% Evaluate Pij, Qi and Ri which define the system of PDEs.
global alpha;

p = zeros(npde,npde);
q = zeros(npde,1);
r = zeros(npde,1);
q(1) = 4.0*alpha*(u(2) + x*ux(2));
q(2) = 0.0;
r(1) = x*ux(1);
r(2) = ux(2) - u(1)*u(2);
p(1,1) = 0.0;
p(1,2) = 0.0;
p(2,1) = 0.0;
p(2,2) = 1.0 - x*x;

function [beta, gamma, ires, user] = bndary(npde, t, u, ux, ibnd, ires, user)
% Evaluate beta and gamma to define the boundary conditions.

if (ibnd == 0)
beta(1) = 0.0;
beta(2) = 1.0;
gamma(1) = u(1);
gamma(2) = -u(1)*u(2);
else
beta(1) = 1.0;
beta(2) = 0.0;
gamma(1) = -u(1);
gamma(2) = u(2);
end

function [u] = uinit(x, npts)
% Set initial values for solution.
global alpha;

for i = 1:npts
u(1,i) = 2.0*alpha*x(i);
u(2,i) = 1.0;
end

function plot_results(x, t, u, ident)
% Formatting for title and axis labels.
titleFmt = {'FontName', 'Helvetica', 'FontWeight', 'Bold', 'FontSize', 14};
labFmt = {'FontName', 'Helvetica', 'FontWeight', 'Bold', 'FontSize', 13};
set(gca, 'FontSize', 13); % for legend, axis tick labels, etc.

% 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', labFmt{:});
ylabel('t', labFmt{:});
zlabel([ident,'(x,t)'], labFmt{:});
title({['Solution ',ident,' of elliptic-parabolic pair'], ...
'using method of lines and BDF'}, titleFmt{:});
title(['Solution ',ident,' of elliptic-parabolic pair'], titleFmt{:});

% 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(-125, 30);
```
```
d03pc example program results

accuracy requirement =  1.00000e-03
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, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013