nag_ode_bvp_fd_lin_gen (d02gbc) (PDF version)
d02 Chapter Contents
d02 Chapter Introduction
NAG Library Manual

NAG Library Function Document

nag_ode_bvp_fd_lin_gen (d02gbc)

 Contents

    1  Purpose
    7  Accuracy

1  Purpose

nag_ode_bvp_fd_lin_gen (d02gbc) solves a general linear two-point boundary value problem for a system of ordinary differential equations using a deferred correction technique.

2  Specification

#include <nag.h>
#include <nagd02.h>
void  nag_ode_bvp_fd_lin_gen (Integer neq,
void (*fcnf)(Integer neq, double x, double f[], Nag_User *comm),
void (*fcng)(Integer neq, double x, double g[], Nag_User *comm),
double a, double b, double c[], double d[], double gam[], Integer mnp, Integer *np, double x[], double y[], double tol, Nag_User *comm, NagError *fail)

3  Description

nag_ode_bvp_fd_lin_gen (d02gbc) solves the linear two-point boundary value problem for a system of neq ordinary differential equations in the interval a,b . The system is written in the form
y = F x y + g x (1)
and the boundary conditions are written in the form
Cy a + Dy b = γ (2)
Here F x , C  and D  are neq by neq matrices, and g x  and γ  are neq component vectors. The approximate solution to (1) and (2) is found using a finite difference method with deferred correction. The algorithm is a specialisation of that used in the function nag_ode_bvp_fd_nonlin_gen (d02rac) which solves a nonlinear version of (1) and (2). The nonlinear version of the algorithm is described fully in Pereyra (1979).
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

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:     neq IntegerInput
On entry: the number of equations; that is neq is the order of system (1).
Constraint: neq2 .
2:     fcnf function, supplied by the userExternal Function
fcnf must evaluate the matrix F x  in (1) at a general point x .
The specification of fcnf is:
void  fcnf (Integer neq, double x, double f[], Nag_User *comm)
1:     neq IntegerInput
On entry: the number of differential equations.
2:     x doubleInput
On entry: the value of the independent variable x .
3:     f[neq×neq] doubleOutput
On exit: the i,j th element of the matrix F x , for i , j = 1 , 2 , , neq  where F ij  is set by f[ i-1 × neq + j-1 ] . (See Section 10 for an example.)
4:     comm Nag_User *
Pointer to a structure of type Nag_User with the following member:
pPointer 
On entry/exit: the pointer commp  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.)
3:     fcng function, supplied by the userExternal Function
fcng must evaluate the vector g x  in (1) at a general point x .
The specification of fcng is:
void  fcng (Integer neq, double x, double g[], Nag_User *comm)
1:     neq IntegerInput
On entry: the number of differential equations.
2:     x doubleInput
On entry: the value of the independent variable x .
3:     g[neq] doubleOutput
On exit: the i th element of the vector g x , for i=1,2,,neq. (See Section 10 for an example.)
4:     comm Nag_User *
Pointer to a structure of type Nag_User with the following member:
pPointer 
On entry/exit: the pointer commp  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.)
If you do not wish to supply fcng the actual argument fcng must be the NAG defined null function pointer NULLFN.
4:     a doubleInput
On entry: the left-hand boundary point, a .
5:     b doubleInput
On entry: the right-hand boundary point, b .
Constraint: b>a .
6:     c[neq×neq] doubleInput/Output
7:     d[neq×neq] doubleInput/Output
8:     gam[neq] doubleInput/Output
On entry: the arrays c and d must be set to the matrices C  and D  in (2). gam must be set to the vector γ  in (2).
On exit: the rows of c and d and the components of gam are re-ordered so that the boundary conditions are in the order:
(i) conditions on y a  only;
(ii) condition involving y a  and y b ; and
(iii) conditions on y b  only.
The function will be slightly more efficient if the arrays c, d and gam are ordered in this way before entry, and in this event they will be unchanged on exit.
Note that the boundary conditions must be of boundary value type, that is neither C  nor D  may be identically zero. Note also that the rank of the matrix C,D  must be neq for the problem to be properly posed. Any violation of these conditions will lead to an error exit.
9:     mnp IntegerInput
On entry: the maximum permitted number of mesh points.
Constraint: mnp32 .
10:   np Integer *Input/Output
On entry: determines whether a default or user-supplied initial mesh is used.
np=0
np is set to a default value of 4 and a corresponding equispaced mesh x[0] , x[1] , , x[np-1]  is used.
np4
You must define an initial mesh using the array x as described.
Constraint: np=0 or 4npmnp.
On exit: the number of points in the final (returned) mesh.
11:   x[mnp] doubleInput/Output
On entry: if np4  (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 , (3)
for np4 .
On exit: x[0] , x[1] , , x[np-1]  define the final mesh (with the returned value of np) satisfying the relation (3).
12:   y[neq×mnp] doubleOutput
On exit: the approximate solution z j x i  satisfying (4), 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.
13:   tol doubleInput
On entry: a positive absolute error tolerance.
If
a = x 1 < x 2 < < x np = b (4)
is the final mesh, z j x i  is the j th component of the approximate solution at x i , and y j x i  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 (5)
Constraint: tol>0.0 .
14:   comm Nag_User *
Pointer to a structure of type Nag_User with the following member:
pPointer 
On entry/exit: the pointer commp, of type Pointer, allows you to communicate information to and from fcnf and fcng. An object of the required type should be declared, e.g., a structure, and its address assigned to the pointer commp 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.
15:   fail NagError *Input/Output
The NAG error argument (see Section 2.7 in How to Use the NAG Library and its Documentation).

6  Error Indicators and Warnings

NE_2_REAL_ARG_LE
On entry, b=value  while a=value . These arguments must satisfy b>a .
NE_ALLOC_FAIL
Dynamic memory allocation failed.
NE_BOUND_COND_COL
More than neq columns of the neq by 2×neq  matrix C,D  are identically zero. i.e., the boundary conditions are rank deficient. The number of non-identically zero columns is value.
NE_BOUND_COND_LC
At least one row of the neq by 2×neq  matrix C,D  is a linear combination of the other rows, i.e., the boundary conditions are rank deficient. The index of the first such row is value.
NE_BOUND_COND_MAT
One of the matrices C  or D  is identically zero, i.e., the problem is of initial value and not of the boundary type.
NE_BOUND_COND_NLC
At least one row of the neq by 2×neq  matrix C,D  is a linear combination of the other rows determined up to a numerical tolerance, i.e., the boundary conditions are rank deficient. The index of first such row is value. There is some doubt as to the rank deficiency of the boundary conditions. However even if the boundary conditions are not rank deficient they are not posed in a suitable form for use with this function. For example, if
C = 1 0 1 ε , D = 1 0 1 0 , γ = γ 1 γ 2  
and ε  is small enough, this error exit is likely to be taken. A better form for the boundary conditions in this case would be
C = 1 0 0 1 , D = 1 0 0 0 , γ = γ 1 ε -1 γ 2 - γ 1  
NE_BOUND_COND_ROW
Row value of the array c and the corresponding row of array d are identically zero, i.e., the boundary conditions are rank deficient.
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, mnp=value.
Constraint: mnp32.
On entry, neq=value.
Constraint: neq2.
NE_INT_RANGE_CONS_2
On entry, np=value  and mnp=value . The argument np must satisfy either 4 np mnp  or 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 x[0] : a=value , x[0] = value.
NE_NOT_STRICTLY_INCREASING
The sequence x is not strictly increasing: x[value] = value, x[value] = value.
NE_REAL_ARG_LE
On entry, tol must not be less than or equal to 0.0: tol=value .
NE_RT_B_MESH
On entry, the right boundary value b, has not been set to x[np-1] : b=value , x[np-1] = value.

7  Accuracy

The solution returned by the function will be accurate to your tolerance as defined by the relation (4) 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.

8  Parallelism and Performance

nag_ode_bvp_fd_lin_gen (d02gbc) is not threaded in any implementation.

9  Further Comments

The time taken by the function depends on the difficulty of the problem, the number of mesh points (and meshes) used and the number of deferred corrections.
In the case where you wish to solve a sequence of similar problems, the use of the final mesh from one case is strongly recommended as the initial mesh for the next.

10  Example

We solve the problem (written as a first order system)
ε y + y = 0  
with boundary conditions
y 0 = 0 , y 1 = 1  
for the cases ε = 10 -1  and ε = 10 -2  using the default initial mesh in the first case, and the final mesh of the first case as initial mesh for the second (more difficult) case. We give the solution and the error at each mesh point to illustrate the accuracy of the method given the accuracy request tol = 1.0e−3 .

10.1  Program Text

Program Text (d02gbce.c)

10.2  Program Data

None.

10.3  Program Results

Program Results (d02gbce.r)


nag_ode_bvp_fd_lin_gen (d02gbc) (PDF version)
d02 Chapter Contents
d02 Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2016