d02 Chapter Contents
d02 Chapter Introduction
NAG C Library Manual

# NAG Library Function Documentnag_ode_bvp_fd_nonlin_fixedbc (d02gac)

## 1  Purpose

nag_ode_bvp_fd_nonlin_fixedbc (d02gac) solves the two-point boundary value problem with assigned boundary values for a system of ordinary differential equations, using a deferred correction technique and a Newton iteration.

## 2  Specification

 #include #include
void  nag_ode_bvp_fd_nonlin_fixedbc (Integer neq,
 void (*fcn)(Integer neq, double x, const double y[], double f[], Nag_User *comm),
double a, double b, const double u[], const Integer v[], Integer mnp, Integer *np, double x[], double y[], double tol, Nag_User *comm, NagError *fail)

## 3  Description

nag_ode_bvp_fd_nonlin_fixedbc (d02gac) solves a two-point boundary value problem for a system of neq differential equations in the interval $\left[a,b\right]$. The system is written in the form
 $y i ′ = f i x , y 1 , y 2 , … , y neq , i = 1 , 2 , … , neq$ (1)
and the derivatives are evaluated by fcn. Initially, neq boundary values of the variables ${y}_{i}$ must be specified (assigned), some at $a$ and some at $b$. You also need to supply estimates of the remaining neq boundary values and all the boundary values are used in constructing an initial approximation to the solution. This approximate solution is corrected by a finite difference technique with deferred correction allied with a Newton iteration to solve the finite difference equations. The technique used is described fully in Pereyra (1979). The Newton iteration requires a Jacobian matrix $\frac{\partial {f}_{i}}{\partial {y}_{j}}$ and this is calculated by numerical differentiation using an algorithm described in Curtis et al. (1974).
You need to supply an absolute error tolerance and may also supply an initial mesh for the construction of the finite difference equations (alternatively a default mesh is used). The algorithm constructs a solution on a mesh defined by adding points to the initial mesh. This solution is chosen so that the error is everywhere less than your tolerance and so that the error is approximately equidistributed on the final mesh. The solution is returned on this final mesh.
If the solution is required at a few specific points then these should be included in the initial mesh. If on the other hand the solution is required at several specific points then you should use the interpolation functions provided in Chapter e01 if these points do not themselves form a convenient mesh.

## 4  References

Curtis A R, Powell M J D and Reid J K (1974) On the estimation of sparse Jacobian matrices J. Inst. Maths. Applics. 13 117–119
Pereyra V (1979) PASVA3: An adaptive finite-difference Fortran program for first order nonlinear, ordinary boundary problems Codes for Boundary Value Problems in Ordinary Differential Equations. Lecture Notes in Computer Science (eds B Childs, M Scott, J W Daniel, E Denman and P Nelson) 76 Springer–Verlag

## 5  Arguments

1:     neqIntegerInput
On entry: the number of equations.
Constraint: ${\mathbf{neq}}\ge 2$.
2:     fcnfunction, supplied by the userExternal Function
fcn must evaluate the functions ${f}_{i}$ (i.e., the derivatives ${y}_{i}^{\prime }$) at the general point $x$.
The specification of fcn is:
 void fcn (Integer neq, double x, const double y[], double f[], Nag_User *comm)
1:     neqIntegerInput
On entry: the number of differential equations.
2:     xdoubleInput
On entry: the value of the argument $x$.
3:     y[neq]const doubleInput
On entry: $y\left[\mathit{i}-1\right]$ holds the value of the argument ${y}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,{\mathbf{neq}}$.
4:     f[neq]doubleOutput
On exit: $f\left[\mathit{i}-1\right]$ must contain the values of ${f}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,{\mathbf{neq}}$.
5:     commNag_User *
Pointer to a structure of type Nag_User with the following member:
pPointer
On entry/exit: the pointer $\mathbf{comm}\mathbf{\to }\mathbf{p}$ should be cast to the required type, e.g., struct user *s = (struct user *)comm → p, to obtain the original object's address with appropriate type. (See the argument comm below.)
On entry: the left-hand boundary point, $a$.
4:     bdoubleInput
On entry: the right-hand boundary point, $b$.
Constraint: ${\mathbf{b}}>{\mathbf{a}}$.
5:     u[${\mathbf{neq}}×2$]const doubleInput
On entry: ${\mathbf{u}}\left[\left(i-1\right)×2+0\right]$ must be set to the known (assigned) or estimated values of ${y}_{i}$ at $a$ and ${\mathbf{u}}\left[\left(\mathit{i}-1\right)×2+1\right]$ must be set to the known or estimated values of ${y}_{\mathit{i}}$ at $b$, for $\mathit{i}=1,2,\dots ,{\mathbf{neq}}$.
6:     v[${\mathbf{neq}}×2$]const IntegerInput
On entry: ${\mathbf{v}}\left[\left(i-1\right)×2+j-1\right]$ must be set to 0 if ${\mathbf{u}}\left[\left(i-1\right)×2+j-1\right]$ is a known (assigned) value and to 1 if ${\mathbf{u}}\left[\left(i-1\right)×2+j-1\right]$ is an estimated value, $i=1,2,\dots ,{\mathbf{neq}}$ and $j=1,2$.
Constraint: precisely neq of the ${\mathbf{v}}\left[\left(i-1\right)×2+j-1\right]$ must be set to 0, i.e., precisely neq of ${\mathbf{u}}\left[\left(i-1\right)×2+0\right]$ and ${\mathbf{u}}\left[\left(i-1\right)×2+1\right]$ must be known values and these must not be all at $a$ or $b$.
7:     mnpIntegerInput
On entry: the maximum permitted number of mesh points.
Constraint: ${\mathbf{mnp}}\ge 32$.
8:     npInteger *Input/Output
On entry: determines whether a default or user-supplied initial mesh is used.
${\mathbf{np}}=0$
np is set to a default value of 4 and a corresponding equispaced mesh ${\mathbf{x}}\left[0\right],{\mathbf{x}}\left[1\right],\dots ,{\mathbf{x}}\left[{\mathbf{np}}-1\right]$ is used.
${\mathbf{np}}\ge 4$
You must define an initial mesh using the array x as described.
Constraint: ${\mathbf{np}}=0$ or $4\le {\mathbf{np}}\le {\mathbf{mnp}}$.
On exit: the number of points in the final (returned) mesh.
9:     x[mnp]doubleInput/Output
On entry: if ${\mathbf{np}}\ge 4$ (see np above), the first np elements must define an initial mesh. Otherwise the elements of x need not be set.
Constraint:
 $a = x[0] < x[1] < ⋯ < x[np-1] = b ​ for ​ np ≥ 4$ (2)
On exit: ${\mathbf{x}}\left[0\right],{\mathbf{x}}\left[1\right],\dots ,{\mathbf{x}}\left[{\mathbf{np}}-1\right]$ define the final mesh (with the returned value of np) satisfying the relation (2).
10:   y[${\mathbf{neq}}×{\mathbf{mnp}}$]doubleOutput
On exit: the approximate solution ${z}_{j}\left({x}_{i}\right)$ satisfying (3), on the final mesh, that is
 $y[j-1×mnp+i-1] = z j x i , i = 1 , 2 , … , np ; ​ j = 1 , 2 , … , neq ,$
where np is the number of points in the final mesh.
The remaining columns of y are not used.
11:   toldoubleInput
On entry: a positive absolute error tolerance. If
 $a = x 1 < x 2 < ⋯ < x np = b$
is the final mesh, ${z}_{j}\left({x}_{i}\right)$ is the $j$th component of the approximate solution at ${x}_{i}$, and ${y}_{j}\left({x}_{i}\right)$ is the $j$th component of the true solution of equation (1) (see Section 3) and the boundary conditions, then, except in extreme cases, it is expected that
 $z j x i - y j x i ≤ tol , i = 1 , 2 , … , np ; ​ j = 1 , 2 , … , neq$ (3)
Constraint: ${\mathbf{tol}}>0.0$.
12:   commNag_User *
Pointer to a structure of type Nag_User with the following member:
pPointer
On entry/exit: the pointer $\mathbf{comm}\mathbf{\to }\mathbf{p}$, of type Pointer, allows you to communicate information to and from fcn. An object of the required type should be declared, e.g., a structure, and its address assigned to the pointer $\mathbf{comm}\mathbf{\to }\mathbf{p}$ by means of a cast to Pointer in the calling program, e.g., comm.p = (Pointer)&s. The type pointer will be void * with a C compiler that defines void * and char * otherwise.
13:   failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

NE_2_REAL_ARG_LE
On entry, ${\mathbf{b}}=〈\mathit{\text{value}}〉$ while ${\mathbf{a}}=〈\mathit{\text{value}}〉$. These arguments must satisfy ${\mathbf{b}}>{\mathbf{a}}$.
NE_ALLOC_FAIL
Dynamic memory allocation failed.
NE_CONV_MESH
A finer mesh is required for the accuracy requested; that is mnp is not large enough.
NE_CONV_MESH_INIT
The Newton iteration failed to converge on the initial mesh. This may be due to the initial mesh having too few points or the initial approximate solution being too inaccurate. Try using nag_ode_bvp_fd_nonlin_gen (d02rac).
NE_CONV_ROUNDOFF
Solution cannot be improved due to roundoff error. Too much accuracy might have been requested.
NE_INT_ARG_LT
On entry, ${\mathbf{mnp}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{mnp}}\ge 32$.
On entry, ${\mathbf{neq}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{neq}}\ge 2$.
NE_INT_RANGE_CONS_2
On entry, ${\mathbf{np}}=〈\mathit{\text{value}}〉$ and ${\mathbf{mnp}}=〈\mathit{\text{value}}〉$. The argument np must satisfy either $4\le {\mathbf{np}}\le {\mathbf{mnp}}$ or ${\mathbf{np}}=0$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
NE_LF_B_MESH
On entry, the left boundary value a, has not been set to ${\mathbf{x}}\left[0\right]$: ${\mathbf{a}}=〈\mathit{\text{value}}〉$, ${\mathbf{x}}\left[0\right]=〈\mathit{\text{value}}〉$.
NE_LF_B_VAL
The number of known left boundary values must be less than the number of equations:
The number of known left boundary values $\text{}=〈\mathit{\text{value}}〉$:
The number of equations $\text{}=〈\mathit{\text{value}}〉$.
NE_LFRT_B_VAL
The sum of known left and right boundary values must equal the number of equations:
The number of known left boundary values $\text{}=〈\mathit{\text{value}}〉$:
The number of known right boundary values $\text{}=〈\mathit{\text{value}}〉$:
The number of equations $\text{}=〈\mathit{\text{value}}〉$.
NE_NOT_STRICTLY_INCREASING
The sequence x is not strictly increasing: ${\mathbf{x}}\left[〈\mathit{\text{value}}〉\right]=〈\mathit{\text{value}}〉$, ${\mathbf{x}}\left[〈\mathit{\text{value}}〉\right]=〈\mathit{\text{value}}〉$.
NE_REAL_ARG_LE
On entry, tol must not be less than or equal to 0.0: ${\mathbf{tol}}=〈\mathit{\text{value}}〉$.
NE_RT_B_MESH
On entry, the right boundary value b, has not been set to ${\mathbf{x}}\left[{\mathbf{np}}-1\right]$: ${\mathbf{b}}=〈\mathit{\text{value}}〉$, ${\mathbf{x}}\left[{\mathbf{np}}-1\right]=〈\mathit{\text{value}}〉$.
NE_RT_B_VAL
The number of known right boundary values must be less than the number of equations:
The number of known right boundary values $\text{}=〈\mathit{\text{value}}〉$:
The number of equations $\text{}=〈\mathit{\text{value}}〉$.

## 7  Accuracy

The solution returned by nag_ode_bvp_fd_nonlin_fixedbc (d02gac) will be accurate to your tolerance as defined by the relation (3) except in extreme circumstances. If too many points are specified in the initial mesh, the solution may be more accurate than requested and the error may not be approximately equidistributed.

The time taken by the function depends on the difficulty of the problem, the number of mesh points used (and the number of different meshes used), the number of Newton iterations and the number of deferred corrections.
A common cause of convergence problems in the Newton iteration is that you are specifying too few points in the initial mesh. Although the function adds points to the mesh to improve accuracy it is unable to do so until the solution on the initial mesh has been calculated in the Newton iteration.
If the known and estimated boundary values are set to zero, the function constructs a zero initial approximation and in many cases the Jacobian is singular when evaluated for this approximation, leading to the breakdown of the Newton iteration.
You may be unable to provide a sufficiently good choice of initial mesh and estimated boundary values, and hence the Newton iteration may never converge. In this case the continuation facility provided in nag_ode_bvp_fd_nonlin_gen (d02rac) is recommended.
In the case where you wish to solve a sequence of similar problems, the final mesh from solving one case is strongly recommended as the initial mesh for the next.

## 9  Example

We solve the differential equation
 $y ′′′ = - yy ′′ - β 1 - y ′ 2$
with boundary conditions
 $y 0 = y ′ 0 = 0 , y ′ 10 = 1$
for $\beta =0.0$ and $\beta =0.2$ to an accuracy specified by ${\mathbf{tol}}=\text{1.0e−3}$. We solve first the simpler problem with $\beta =0.0$ using an equispaced mesh of 26 points and then we solve the problem with $\beta =0.2$ using the final mesh from the first problem.

### 9.1  Program Text

Program Text (d02gace.c)

None.

### 9.3  Program Results

Program Results (d02gace.r)