NAG FL Interface
d02jbf (bvp_​coll_​sys)

Settings help

FL Name Style:


FL Specification Language:


1 Purpose

d02jbf solves a regular linear two-point boundary value problem for a system of ordinary differential equations by Chebyshev series using collocation and least squares.

2 Specification

Fortran Interface
Subroutine d02jbf ( n, cf, bc, x0, x1, k1, kp, c, ldc, w, lw, iw, liw, ifail)
Integer, Intent (In) :: n, k1, kp, ldc, lw, liw
Integer, Intent (Inout) :: ifail
Integer, Intent (Out) :: iw(liw)
Real (Kind=nag_wp), External :: cf
Real (Kind=nag_wp), Intent (In) :: x0, x1
Real (Kind=nag_wp), Intent (Inout) :: c(ldc,n)
Real (Kind=nag_wp), Intent (Out) :: w(lw)
External :: bc
C Header Interface
#include <nag.h>
void  d02jbf_ (const Integer *n,
double (NAG_CALL *cf)(const Integer *i, const Integer *j, const double *x),
void (NAG_CALL *bc)(const Integer *i, Integer *j, double *rhs),
const double *x0, const double *x1, const Integer *k1, const Integer *kp, double c[], const Integer *ldc, double w[], const Integer *lw, Integer iw[], const Integer *liw, Integer *ifail)
The routine may be called by the names d02jbf or nagf_ode_bvp_coll_sys.

3 Description

d02jbf calculates the solution of a regular two-point boundary value problem for a regular linear nth-order system of first-order ordinary differential equations as a Chebyshev series in the interval (x0,x1). The differential equation
y=A(x)y+r(x)  
is defined by cf, and the boundary conditions at the points x0 and x1 are defined by bc.
You specify the degree of Chebyshev series required, k1-1, and the number of collocation points, kp. The routine sets up a system of linear equations for the Chebyshev coefficients, n equations for each collocation point and one for each boundary condition. The boundary conditions are solved exactly, and the remaining equations are then solved by a least squares method. The result produced is a set of coefficients for a Chebyshev series solution for each component of the solution of the system of differential equations on an interval normalized to (-1,1).
e02akf can be used to evaluate the components of the solution at any point on the interval (x0,x1). e02ahf followed by e02akf can be used to evaluate their derivatives.

4 References

Picken S M (1970) Algorithms for the solution of differential equations in Chebyshev-series by the selected points method Report Math. 94 National Physical Laboratory

5 Arguments

1: n Integer Input
On entry: n, the order of the system of differential equations.
Constraint: n1.
2: cf real (Kind=nag_wp) Function, supplied by the user. External Procedure
cf defines the system of differential equations (see Section 3). It must return the value of a coefficient function ai,j(x), of A, at a given point x, or of a right-hand side function ri(x) if j=0.
The specification of cf is:
Fortran Interface
Function cf ( i, j, x)
Real (Kind=nag_wp) :: cf
Integer, Intent (In) :: i, j
Real (Kind=nag_wp), Intent (In) :: x
C Header Interface
double  cf (const Integer *i, const Integer *j, const double *x)
1: i Integer Input
2: j Integer Input
On entry: indicate the function to be evaluated, namely ai,j(x) if 1jn, or ri(x) if j=0.
1in, 0jn.
3: x Real (Kind=nag_wp) Input
On entry: the point at which the function is to be evaluated.
cf must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which d02jbf is called. Arguments denoted as Input must not be changed by this procedure.
Note: cf should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by d02jbf. If your code inadvertently does return any NaNs or infinities, d02jbf is likely to produce unexpected results.
3: bc Subroutine, supplied by the user. External Procedure
bc defines the n boundary conditions, which have the form yk(x0)=s or yk(x1)=s. The boundary conditions may be specified in any order.
The specification of bc is:
Fortran Interface
Subroutine bc ( i, j, rhs)
Integer, Intent (In) :: i
Integer, Intent (Out) :: j
Real (Kind=nag_wp), Intent (Out) :: rhs
C Header Interface
void  bc (const Integer *i, Integer *j, double *rhs)
1: i Integer Input
On entry: the index of the boundary condition to be defined.
2: j Integer Output
On exit: must be set to -k if the ith boundary condition is yk(x0)=s, or to +k if it is yk(x1)=s.
j must not be set to the same value k for two different values of i.
3: rhs Real (Kind=nag_wp) Output
On exit: the value s.
bc must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which d02jbf is called. Arguments denoted as Input must not be changed by this procedure.
Note: bc should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by d02jbf. If your code inadvertently does return any NaNs or infinities, d02jbf is likely to produce unexpected results.
4: x0 Real (Kind=nag_wp) Input
5: x1 Real (Kind=nag_wp) Input
On entry: the left- and right-hand boundaries, x0 and x1, respectively.
Constraint: x1>x0.
6: k1 Integer Input
On entry: the number of coefficients to be returned in the Chebyshev series representation of the components of the solution (hence the degree of the polynomial approximation is k1-1).
Constraint: k12.
7: kp Integer Input
On entry: the number of collocation points to be used.
Constraint: kpk1-1.
8: c(ldc,n) Real (Kind=nag_wp) array Output
On exit: the computed Chebyshev coefficients of the kth component of the solution, yk; that is, the computed solution is:
yk=i=1k1c(i,k)Ti-1(x),  1kn  
where Ti(x) is the ith Chebyshev polynomial of the first kind, and denotes that the first coefficient, c(1,k), is halved.
9: ldc Integer Input
On entry: the first dimension of the array c as declared in the (sub)program from which d02jbf is called.
Constraint: ldck1.
10: w(lw) Real (Kind=nag_wp) array Workspace
11: lw Integer Input
On entry: the dimension of the array w as declared in the (sub)program from which d02jbf is called.
Constraint: lw2×n×(kp+1)×(n×k1+1)+7×n×k1.
12: iw(liw) Integer array Workspace
13: liw Integer Input
On entry: the dimension of the array iw as declared in the (sub)program from which d02jbf is called.
Constraint: liwn×(k1+2).
14: ifail Integer Input/Output
On entry: ifail must be set to 0, -1 or 1 to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of 0 causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of -1 means that an error message is printed while a value of 1 means that it is not.
If halting is not appropriate, the value -1 or 1 is recommended. If message printing is undesirable, then the value 1 is recommended. Otherwise, the value 0 is recommended. When the value -1 or 1 is used it is essential to test the value of ifail on exit.
On exit: ifail=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6 Error Indicators and Warnings

If on entry ifail=0 or -1, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
ifail=1
On entry, k1=value.
Constraint: k12.
On entry, kp=value and k1=value.
Constraint: kp+1k1.
On entry, n=value.
Constraint: n1.
On entry, x1=value and x0=value.
Constraint: x1>x0.
ifail=2
On entry, liw=value.
Constraint: liwn×k1+2×n; that is, value.
On entry, lw=value.
Constraint: lw2×n×(kp+1)×(n×k1+1)+7×n×k1; that is, value.
ifail=3
Either the boundary conditions are not linearly independent, or the coefficient matrix is rank deficient. Increasing the number of collocation points may overcome this latter problem.
ifail=4
Iterative refinement in the least squares solution has failed to converge. The coefficient matrix is too ill-conditioned.
ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
ifail=-399
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
ifail=-999
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

7 Accuracy

The Chebyshev coefficients are determined by a stable numerical method. The accuracy of the approximate solution may be checked by varying the degree of the polynomials and the number of collocation points (see Section 9).

8 Parallelism and Performance

d02jbf is not thread safe and should not be called from a multithreaded user program. Please see Section 1 in FL Interface Multithreading for more information on thread safety.
d02jbf makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

9 Further Comments

The time taken by d02jbf depends on the size and complexity of the differential system, the degree of the polynomial solution, and the number of matching points.
The collocation points in the interval (x0,x1) are chosen to be the extrema of the appropriate shifted Chebyshev polynomial. If kp=k1-1, then the least squares solution reduces to the solution of a system of linear equations, and true collocation results.
The accuracy of the solution may be checked by repeating the calculation with different values of k1 and with kp fixed but kpk1-1. If the Chebyshev coefficients decrease rapidly for each component (and consistently for various k1 and kp), the size of the last two or three gives an indication of the error. If the Chebyshev coefficients do not decay rapidly, it is likely that the solution cannot be well-represented by Chebyshev series. Note that the Chebyshev coefficients are calculated for the interval (-1,1).
Linear systems of high-order equations in their original form, singular problems, and, indirectly, nonlinear problems can be solved using d02tgf.

10 Example

This example solves the equation
y + y = 1  
with boundary conditions
y(-1) = y(1) = 0 .  
The equation is written as the first-order system
( y1 y2 ) = ( 0 1 -1 0 ) ( y1 y2 ) + ( 0 1 )  
for solution by d02jbf and the boundary conditions are written
y1(-1)=y1(1)=0.  
We use k1=4, 6 and 8, and kp=10 and 15, so that the different Chebyshev series may be compared. The solution for k1=8 and kp=15 is evaluated by e02akf at nine equally spaced points over the interval (-1,1).

10.1 Program Text

Program Text (d02jbfe.f90)

10.2 Program Data

Program Data (d02jbfe.d)

10.3 Program Results

Program Results (d02jbfe.r)
GnuplotProduced by GNUPLOT 4.6 patchlevel 3 −2 −1.5 −1 −0.5 0 0.5 1 1.5 2 −1 −0.5 0 0.5 1 0 5e−05 0.0001 0.00015 0.0002 Solution Abolute Error x Example Program Two-point Boundary-value Problem for ODE System by Chebyshev-series using Collocation and Least-squares y y' error gnuplot_plot_1 gnuplot_plot_2 gnuplot_plot_3