D02JAF (PDF version)
D02 Chapter Contents
D02 Chapter Introduction
NAG Library Manual

NAG Library Routine Document

D02JAF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

 Contents

    1  Purpose
    7  Accuracy

1  Purpose

D02JAF solves a regular linear two-point boundary value problem for a single nth-order ordinary differential equation by Chebyshev series using collocation and least squares.

2  Specification

SUBROUTINE D02JAF ( N, CF, BC, X0, X1, K1, KP, C, W, LW, IW, IFAIL)
INTEGER  N, K1, KP, LW, IW(K1), IFAIL
REAL (KIND=nag_wp)  CF, X0, X1, C(K1), W(LW)
EXTERNAL  CF, BC

3  Description

D02JAF calculates the solution of a regular two-point boundary value problem for a single nth-order linear ordinary differential equation as a Chebyshev series in the interval x0,x1. The differential equation
fn+1xy n x+fnxy n-1 x++f1xyx=f0x  
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, one equation 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 of the differential equation on an interval normalized to -1,1.
E02AKF can be used to evaluate the solution at any point on the interval x0,x1 – see Section 10 for an example. E02AHF followed by E02AKF can be used to evaluate its 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 – INTEGERInput
On entry: n, the order of the differential equation.
Constraint: N1.
2:     CF – REAL (KIND=nag_wp) FUNCTION, supplied by the user.External Procedure
CF defines the differential equation (see Section 3). It must return the value of a function fjx at a given point x, where, for 1jn+1, fjx is the coefficient of y j-1 x in the equation, and f0x is the right-hand side.
The specification of CF is:
FUNCTION CF ( J, X)
REAL (KIND=nag_wp) CF
INTEGER  J
REAL (KIND=nag_wp)  X
1:     J – INTEGERInput
On entry: the index of the function fj to be evaluated.
2:     X – REAL (KIND=nag_wp)Input
On entry: the point at which fj is to be evaluated.
CF must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which D02JAF is called. Arguments denoted as Input must not be changed by this procedure.
3:     BC – SUBROUTINE, supplied by the user.External Procedure
BC defines the boundary conditions, each of which has the form y k-1x1=sk or yk-1x0=sk. The boundary conditions may be specified in any order.
The specification of BC is:
SUBROUTINE BC ( I, J, RHS)
INTEGER  I, J
REAL (KIND=nag_wp)  RHS
1:     I – INTEGERInput
On entry: the index of the boundary condition to be defined.
2:     J – INTEGEROutput
On exit: must be set to -k if the boundary condition is y k-1 x0=sk, and to +k if it is y k-1 x1=sk.
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: must be set to the value sk.
BC must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which D02JAF is called. Arguments denoted as Input must not be changed by this procedure.
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 – INTEGERInput
On entry: the number of coefficients to be returned in the Chebyshev series representation of the solution (hence the degree of the polynomial approximation is K1-1).
Constraint: K1N+1.
7:     KP – INTEGERInput
On entry: the number of collocation points to be used.
Constraint: KPK1-N.
8:     CK1 – REAL (KIND=nag_wp) arrayOutput
On exit: the computed Chebyshev coefficients; that is, the computed solution is:
i=1K1CiTi-1x  
where Tix is the ith Chebyshev polynomial of the first kind, and  denotes that the first coefficient, C1, is halved.
9:     WLW – REAL (KIND=nag_wp) arrayWorkspace
10:   LW – INTEGERInput
On entry: the dimension of the array W as declared in the (sub)program from which D02JAF is called.
Constraint: LW2×KP+N×K1+1+7×K1.
11:   IWK1 – INTEGER arrayWorkspace
12:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to 0, -1​ or ​1. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1​ or ​1 is recommended. If the output of error messages is undesirable, then the value 1 is recommended. Otherwise, if you are not familiar with this argument, the recommended value is 0. 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,N<1,
orX0X1,
orK1<N+1,
orKP<K1-N.
IFAIL=2
On entry,LW<2×KP+N×K1+1+7×K1 (insufficient workspace).
IFAIL=3
Either the boundary conditions are not linearly independent (that is, in BC the variable J is set to the same value k for two different values of I), or the rank of the matrix of equations for the coefficients is less than the number of unknowns. Increasing KP may overcome this latter problem.
IFAIL=4
The least squares routine F04AMF has failed to correct the first approximate solution (see F04AMF).
IFAIL=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
IFAIL=-399
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
IFAIL=-999
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation 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 polynomial and the number of collocation points (see Section 9).

8  Parallelism and Performance

D02JAF is not thread safe and should not be called from a multithreaded user program. Please see Section 3.12.1 in How to Use the NAG Library and its Documentation for more information on thread safety.
D02JAF 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 D02JAF depends on the complexity of the differential equation, 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-N, 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-N. If the Chebyshev coefficients decrease rapidly (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.
Systems of regular linear differential equations can be solved using D02JBF. It is necessary before using D02JBF to write the differential equations as a first-order system. 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 = y1 = 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 (d02jafe.f90)

10.2  Program Data

Program Data (d02jafe.d)

10.3  Program Results

Program Results (d02jafe.r)

GnuplotProduced by GNUPLOT 4.6 patchlevel 3 −0.9 −0.8 −0.7 −0.6 −0.5 −0.4 −0.3 −0.2 −0.1 0 −1 −0.5 0 0.5 1 y x Example Program Two-point Boundary-value Problem for ODE by Chebyshev-series using Collocation and Least-squares gnuplot_plot_1

D02JAF (PDF version)
D02 Chapter Contents
D02 Chapter Introduction
NAG Library Manual

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