NAG FL Interface
d02tgf (bvp_​coll_​nth_​comp)

Settings help

FL Name Style:


FL Specification Language:


1 Purpose

d02tgf solves a system of linear ordinary differential equations by least squares fitting of a series of Chebyshev polynomials using collocation.

2 Specification

Fortran Interface
Subroutine d02tgf ( n, m, l, x0, x1, k1, kp, c, ldc, coeff, bdyc, w, lw, iw, liw, ifail)
Integer, Intent (In) :: n, m(n), l(n), k1, kp, ldc, lw, liw
Integer, Intent (Inout) :: ifail
Integer, Intent (Out) :: iw(liw)
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 :: coeff, bdyc
C Header Interface
#include <nag.h>
void  d02tgf_ (const Integer *n, const Integer m[], const Integer l[], const double *x0, const double *x1, const Integer *k1, const Integer *kp, double c[], const Integer *ldc,
void (NAG_CALL *coeff)(const double *x, const Integer *i, double a[], const Integer *ia, const Integer *ia1, double *rhs),
void (NAG_CALL *bdyc)(double *x, const Integer *i, const Integer *j, double a[], const Integer *ia, const Integer *ia1, double *rhs),
double w[], const Integer *lw, Integer iw[], const Integer *liw, Integer *ifail)
The routine may be called by the names d02tgf or nagf_ode_bvp_coll_nth_comp.

3 Description

d02tgf calculates an approximate solution of a linear or linearized system of ordinary differential equations as a Chebyshev series. Suppose there are n differential equations for n variables y1,y2,,yn, over the range (x0,x1). Let the ith equation be
j=1 mi+1 k=1 n fkji(x) y k(j-1) (x)= ri(x)  
where yk (j) (x)=djyk(x) dxj . coeff evaluates the coefficients fkji(x) and the right-hand side ri(x) for each i, 1in, at any point x. The boundary conditions may be applied either at the end points or at intermediate points; they are written in the same form as the differential equations, and specified by bdyc. For example the jth boundary condition out of those associated with the ith differential equation takes the form
j=1 li+1 k=1 n f kj ij (xij) yk(j-1) (xij)=rij (xij) ,  
where xij lies between x0 and x1. It is assumed in this routine that certain of the boundary conditions are associated with each differential equation. This is for your convenience; the grouping does not affect the results.
The degree of the polynomial solution must be the same for all variables. You specify the degree required, k1-1, and the number of collocation points, kp, in the range. The routine sets up a system of linear equations for the Chebyshev coefficients, with n equations for each collocation point and one for each boundary condition. The collocation points are chosen at the extrema of a shifted Chebyshev polynomial of degree kp-1. The boundary conditions are satisfied exactly, and the remaining equations are solved by a least squares method. The result produced is a set of Chebyshev coefficients for the n functions y1,y2,,yn, with the range normalized to [−1,1].
e02akf can be used to evaluate the components of the solution at any point on the range [x0,x1]. e02ahf and e02ajf may be used to obtain Chebyshev series representations of derivatives and integrals (respectively) of the components of the solution.

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 number of differential equations in the system.
Constraint: n1.
2: m(n) Integer array Input
On entry: m(i) must be set to the highest order derivative occurring in the ith equation, for i=1,2,,n.
Constraint: m(i)1, for i=1,2,,n.
3: l(n) Integer array Input
On entry: l(i) must be set to the number of boundary conditions associated with the ith equation, for i=1,2,,n.
Constraint: l(i)0, for i=1,2,,n.
4: x0 Real (Kind=nag_wp) Input
On entry: the left-hand boundary, x0.
5: x1 Real (Kind=nag_wp) Input
On entry: the right-hand boundary, x1.
Constraint: x1>x0.
6: k1 Integer Input
On entry: the number of coefficients, k1, to be returned in the Chebyshev series representation of the solution (hence, the degree of the polynomial approximation is k1-1).
Constraint: k11+ max 1in m(i).
7: kp Integer Input
On entry: the number of collocation points to be used, kp.
Constraint: n×kpn×k1+ i=1 n l(i) .
8: c(ldc,n) Real (Kind=nag_wp) array Output
On exit: the kth column of c contains 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 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 d02tgf is called.
Constraint: ldck1.
10: coeff Subroutine, supplied by the user. External Procedure
coeff defines the system of differential equations (see Section 3). It must evaluate the coefficient functions fkji(x) and the right-hand side function ri(x) of the ith equation at a given point. Only nonzero entries of the array a and rhs need be specifically assigned, since all elements are set to zero by d02tgf before calling coeff.
The specification of coeff is:
Fortran Interface
Subroutine coeff ( x, i, a, ia, ia1, rhs)
Integer, Intent (In) :: i, ia, ia1
Real (Kind=nag_wp), Intent (In) :: x
Real (Kind=nag_wp), Intent (Inout) :: a(ia,ia1), rhs
C Header Interface
void  coeff (const double *x, const Integer *i, double a[], const Integer *ia, const Integer *ia1, double *rhs)
Important: the dimension declaration for a must contain the variable ia, not an integer constant.
1: x Real (Kind=nag_wp) Input
On entry: x, the point at which the functions must be evaluated.
2: i Integer Input
On entry: the equation for which the coefficients and right-hand side are to be evaluated.
3: a(ia,ia1) Real (Kind=nag_wp) array Input/Output
On entry: all elements of a are set to zero.
On exit: a(k,j) must contain the value fkji(x), for 1kn, 1jmi+1.
4: ia Integer Input
5: ia1 Integer Input
On entry: the first dimension of the array a and the second dimension of the array a as declared in the (sub)program from which d02tgf is called.
6: rhs Real (Kind=nag_wp) Input/Output
On entry: is set to zero.
On exit: it must contain the value ri(x).
coeff must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which d02tgf is called. Arguments denoted as Input must not be changed by this procedure.
Note: coeff should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by d02tgf. If your code inadvertently does return any NaNs or infinities, d02tgf is likely to produce unexpected results.
11: bdyc Subroutine, supplied by the user. External Procedure
bdyc defines the boundary conditions (see Section 3). It must evaluate the coefficient functions fkj ij and right-hand side function rij in the jth boundary condition associated with the ith equation, at the point xij at which the boundary condition is applied. Only nonzero entries of the array a and rhs need be specifically assigned, since all elements are set to zero by d02tgf before calling bdyc.
The specification of bdyc is:
Fortran Interface
Subroutine bdyc ( x, i, j, a, ia, ia1, rhs)
Integer, Intent (In) :: i, j, ia, ia1
Real (Kind=nag_wp), Intent (Inout) :: a(ia,ia1), rhs
Real (Kind=nag_wp), Intent (Out) :: x
C Header Interface
void  bdyc (double *x, const Integer *i, const Integer *j, double a[], const Integer *ia, const Integer *ia1, double *rhs)
Important: the dimension declaration for a must contain the variable ia, not an integer constant.
1: x Real (Kind=nag_wp) Output
On exit: xij, the value at which the boundary condition is applied.
2: i Integer Input
On entry: the differential equation with which the condition is associated.
3: j Integer Input
On entry: the boundary condition for which the coefficients and right-hand side are to be evaluated.
4: a(ia,ia1) Real (Kind=nag_wp) array Input/Output
On entry: all elements of a are set to zero.
On exit: the value f kj ij (xij) , for 1kn, 1jmi+1.
5: ia Integer Input
6: ia1 Integer Input
On entry: the first dimension of the array a and the second dimension of the array a as declared in the (sub)program from which d02tgf is called.
7: rhs Real (Kind=nag_wp) Input/Output
On entry: is set to zero.
On exit: the value rij (xij) .
bdyc must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which d02tgf is called. Arguments denoted as Input must not be changed by this procedure.
Note: bdyc should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by d02tgf. If your code inadvertently does return any NaNs or infinities, d02tgf is likely to produce unexpected results.
12: w(lw) Real (Kind=nag_wp) array Workspace
13: lw Integer Input
On entry: the dimension of the array w as declared in the (sub)program from which d02tgf is called.
Constraint: lw2× (n×kp+NL)× (n×k1+1) + 7×n×k1 , where NL= i=1 n l(i) .
14: iw(liw) Integer array Workspace
15: liw Integer Input
On entry: the dimension of the array iw as declared in the (sub)program from which d02tgf is called.
Constraint: liwn×k1+1.
16: 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, a negative number of boundary conditions was set for one of the system equations.
On entry, k1=value and maxm(i)=value.
Constraint: k11+maxm(i).
On entry, kp=value and k1=value.
Constraint: kp+1k1.
On entry, ldc=value and k1=value.
Constraint: ldck1.
On entry, n=value.
Constraint: n1.
On entry, one of the equations is of order less than 1.
On entry, x1=value and x0=value.
Constraint: x1>x0.
ifail=2
On entry, liw=value and n×k1+2×n=value.
Constraint: liwn×k1+2×n.
On entry, lw=value and 2×n×(kp+1)×(n×k1+1)+7×n×k1=value.
Constraint: lw2×n×(kp+1)×(n×k1+1)+7×n×k1.
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

Estimates of the accuracy of the solution may be obtained by using the checks described in Section 9. The Chebyshev coefficients are calculated by a stable numerical method.

8 Parallelism and Performance

Background information to multithreading can be found in the Multithreading documentation.
d02tgf 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 d02tgf depends on the complexity of the system of differential equations, the degree of the polynomial solution and the number of matching points.
If the number of matching points kp is equal to the number of coefficients k1 minus the average number of boundary conditions 1n i=1 n li , then the least squares solution reduces to simple solution of linear equations and true collocation results. The accuracy of the solution may be checked by repeating the calculation with different values of k1. If the Chebyshev coefficients decrease rapidly, the size of the last two or three gives an indication of the error. If they do not decrease rapidly, it may be desirable to use a different method. Note that the Chebyshev coefficients are calculated for the range normalized to [−1,1].
Generally the number of boundary conditions required is equal to the sum of the orders of the n differential equations. However, in some cases fewer boundary conditions are needed, because the assumption of a polynomial solution is equivalent to one or more boundary conditions (since it excludes singular solutions).
A system of nonlinear differential equations must be linearized before using the routine. The calculation is repeated iteratively. On each iteration the linearized equation is used. For a starting approximation, we may take, say, a linear function, and set up the appropriate Chebyshev coefficients before starting the iteration. For example, if y1=ax+b in the range (x0,x1), we set B, the array of coefficients,
In some cases a better initial approximation may be needed and can be obtained by using e02adf or e02aff to obtain a Chebyshev series for an approximate solution. The coefficients of the current iterate must be communicated to coeff and bdyc, for example using global variables. The convergence of the (Newton) iteration cannot be guaranteed in general, though it is usually satisfactory from a good starting approximation.

10 Example

This example solves the nonlinear system
2y1+(y22-1) y1+y2=0, 2y2-y1=0,  
in the range (−1,1), with y1=0, y2=3, y2=0 at x=−1.
Suppose an approximate solution is z1, z2 such that y1z1, y2z2: then the first equation gives, on linearizing,
2y1+(z22-1) y1+(2z1z2+1) y2=2z1z22.  
The starting approximation is taken to be z1=0, z2=3. In the program below, the array B is used to hold the coefficients of the previous iterate (or of the starting approximation). We iterate until the Chebyshev coefficients converge to five figures. e02akf is used to calculate the solution from its Chebyshev coefficients.

10.1 Program Text

Program Text (d02tgfe.f90)

10.2 Program Data

Program Data (d02tgfe.d)

10.3 Program Results

Program Results (d02tgfe.r)
GnuplotProduced by GNUPLOT 5.4 patchlevel 6 −0.5 −0.4 −0.3 −0.2 −0.1 0 0.1 −1 −0.5 0 0.5 1 2.6 2.7 2.8 2.9 3 3.1 3.2 y1 y2 y1 y2 x y1 y2 Example Program Solution of Linearised System by Chebyshev Collocation