NAG Library Routine Document
d02tgf (bvp_coll_nth_comp)
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 <nagmk26.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) 

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
${y}_{1},{y}_{2},\dots ,{y}_{n}$, over the range
$\left({x}_{0},{x}_{1}\right)$. Let the
$i$th equation be
where
${y}_{k}^{\left(j\right)}\left(x\right)=\frac{{d}^{j}{y}_{k}\left(x\right)}{d{x}^{j}}$.
coeff evaluates the coefficients
${f}_{kj}^{i}\left(x\right)$ and the righthand side
${r}^{i}\left(x\right)$ for each
$i$,
$1\le i\le n$, 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
$j$th boundary condition out of those associated with the
$i$th differential equation takes the form
where
${x}^{ij}$ lies between
${x}_{0}$ and
${x}_{1}$. 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, ${k}_{1}1$, and the number of collocation points, ${k}_{p}$, 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 ${k}_{p}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 ${y}_{1},{y}_{2},\dots ,{y}_{n}$, with the range normalized to $\left[1,1\right]$.
e02akf can be used to evaluate the components of the solution at any point on the range
$\left[{x}_{0},{x}_{1}\right]$ (see
Section 10 for an example).
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 Chebyshevseries by the selected points method Report Math. 94 National Physical Laboratory
5
Arguments
 1: $\mathbf{n}$ – IntegerInput

On entry: $n$, the number of differential equations in the system.
Constraint:
${\mathbf{n}}\ge 1$.
 2: $\mathbf{m}\left({\mathbf{n}}\right)$ – Integer arrayInput

On entry: ${\mathbf{m}}\left(\mathit{i}\right)$ must be set to the highest order derivative occurring in the $\mathit{i}$th equation, for $\mathit{i}=1,2,\dots ,n$.
Constraint:
${\mathbf{m}}\left(\mathit{i}\right)\ge 1$, for $\mathit{i}=1,2,\dots ,n$.
 3: $\mathbf{l}\left({\mathbf{n}}\right)$ – Integer arrayInput

On entry: ${\mathbf{l}}\left(\mathit{i}\right)$ must be set to the number of boundary conditions associated with the $\mathit{i}$th equation, for $\mathit{i}=1,2,\dots ,n$.
Constraint:
${\mathbf{l}}\left(\mathit{i}\right)\ge 0$, for $\mathit{i}=1,2,\dots ,n$.
 4: $\mathbf{x0}$ – Real (Kind=nag_wp)Input

On entry: the lefthand boundary, ${x}_{0}$.
 5: $\mathbf{x1}$ – Real (Kind=nag_wp)Input

On entry: the righthand boundary, ${x}_{1}$.
Constraint:
${\mathbf{x1}}>{\mathbf{x0}}$.
 6: $\mathbf{k1}$ – IntegerInput

On entry: the number of coefficients, ${k}_{1}$, to be returned in the Chebyshev series representation of the solution (hence, the degree of the polynomial approximation is ${\mathbf{k1}}1$).
Constraint:
${\mathbf{k1}}\ge 1+{\displaystyle \underset{1\le i\le {\mathbf{n}}}{\mathrm{max}}}\phantom{\rule{0.25em}{0ex}}{\mathbf{m}}\left(i\right)$.
 7: $\mathbf{kp}$ – IntegerInput

On entry: the number of collocation points to be used, ${k}_{p}$.
Constraint:
${\mathbf{n}}\times {\mathbf{kp}}\ge {\mathbf{n}}\times {\mathbf{k1}}+{\displaystyle \sum _{i=1}^{{\mathbf{n}}}}{\mathbf{l}}\left(i\right)$.
 8: $\mathbf{c}\left({\mathbf{ldc}},{\mathbf{n}}\right)$ – Real (Kind=nag_wp) arrayOutput

On exit: the
$k$th column of
c contains the computed Chebyshev coefficients of the
$k$th component of the solution,
${y}_{k}$; that is, the computed solution is:
where
${T}_{i}\left(x\right)$ is the Chebyshev polynomial of the first kind and
${\sum}^{\prime}$ denotes that the first coefficient,
${\mathbf{c}}\left(1,k\right)$, is halved.
 9: $\mathbf{ldc}$ – IntegerInput

On entry: the first dimension of the array
c as declared in the (sub)program from which
d02tgf is called.
Constraint:
${\mathbf{ldc}}\ge {\mathbf{k1}}$.
 10: $\mathbf{coeff}$ – Subroutine, supplied by the user.External Procedure

coeff defines the system of differential equations (see
Section 3). It must evaluate the coefficient functions
${f}_{kj}^{i}\left(x\right)$ and the righthand side function
${r}^{i}\left(x\right)$ of the
$i$th 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
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
#include <nagmk26.h>
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: $\mathbf{x}$ – Real (Kind=nag_wp)Input

On entry: $x$, the point at which the functions must be evaluated.
 2: $\mathbf{i}$ – IntegerInput

On entry: the equation for which the coefficients and righthand side are to be evaluated.
 3: $\mathbf{a}\left({\mathbf{ia}},{\mathbf{ia1}}\right)$ – Real (Kind=nag_wp) arrayInput/Output

On entry: all elements of
a are set to zero.
On exit: ${\mathbf{a}}\left(k,j\right)$ must contain the value ${f}_{kj}^{i}\left(x\right)$, for $1\le k\le n$, $1\le j\le {m}_{i}+1$.
 4: $\mathbf{ia}$ – IntegerInput
 5: $\mathbf{ia1}$ – IntegerInput

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: $\mathbf{rhs}$ – Real (Kind=nag_wp)Input/Output

On entry: is set to zero.
On exit: it must contain the value ${r}^{i}\left(x\right)$.
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 floatingpoint 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: $\mathbf{bdyc}$ – Subroutine, supplied by the user.External Procedure

bdyc defines the boundary conditions (see
Section 3). It must evaluate the coefficient functions
${f}_{kj}^{ij}$ and righthand side function
${r}^{ij}$ in the
$j$th boundary condition associated with the
$i$th equation, at the point
${x}^{ij}$ 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
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
#include <nagmk26.h>
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: $\mathbf{x}$ – Real (Kind=nag_wp)Output

On exit: ${x}^{ij}$, the value at which the boundary condition is applied.
 2: $\mathbf{i}$ – IntegerInput

On entry: the differential equation with which the condition is associated.
 3: $\mathbf{j}$ – IntegerInput

On entry: the boundary condition for which the coefficients and righthand side are to be evaluated.
 4: $\mathbf{a}\left({\mathbf{ia}},{\mathbf{ia1}}\right)$ – Real (Kind=nag_wp) arrayInput/Output

On entry: all elements of
a are set to zero.
On exit: the value ${f}_{kj}^{ij}\left({x}^{ij}\right)$, for $1\le k\le n$, $1\le j\le {m}_{i}+1$.
 5: $\mathbf{ia}$ – IntegerInput
 6: $\mathbf{ia1}$ – IntegerInput

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: $\mathbf{rhs}$ – Real (Kind=nag_wp)Input/Output

On entry: is set to zero.
On exit: the value ${r}^{ij}\left({x}^{ij}\right)$.
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 floatingpoint 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: $\mathbf{w}\left({\mathbf{lw}}\right)$ – Real (Kind=nag_wp) arrayWorkspace
 13: $\mathbf{lw}$ – IntegerInput

On entry: the dimension of the array
w as declared in the (sub)program from which
d02tgf is called.
Constraint:
${\mathbf{lw}}\ge 2\times \left({\mathbf{n}}\times {\mathbf{kp}}+\mathit{NL}\right)\times \left({\mathbf{n}}\times {\mathbf{k1}}+1\right)+7\times {\mathbf{n}}\times {\mathbf{k1}}$, where $\mathit{NL}={\displaystyle \sum _{i=1}^{n}}{\mathbf{l}}\left(i\right)$.
 14: $\mathbf{iw}\left({\mathbf{liw}}\right)$ – Integer arrayWorkspace
 15: $\mathbf{liw}$ – IntegerInput

On entry: the dimension of the array
iw as declared in the (sub)program from which
d02tgf is called.
Constraint:
${\mathbf{liw}}\ge {\mathbf{n}}\times {\mathbf{k1}}+1$.
 16: $\mathbf{ifail}$ – IntegerInput/Output

On entry:
ifail must be set to
$0$,
$1\text{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\text{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 $\mathbf{1}\text{or}\mathbf{1}$ is used it is essential to test the value of ifail on exit.
On exit:
${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see
Section 6).
6
Error Indicators and Warnings
If on entry
${\mathbf{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:
 ${\mathbf{ifail}}=1$

On entry, a negative number of boundary conditions was set for one of the system equations.
On entry, ${\mathbf{k1}}=\u2329\mathit{\text{value}}\u232a$ and $\mathrm{max}\phantom{\rule{0.25em}{0ex}}{\mathbf{m}}\left(i\right)=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{k1}}\ge 1+\mathrm{max}\phantom{\rule{0.25em}{0ex}}{\mathbf{m}}\left(i\right)$.
On entry, ${\mathbf{kp}}=\u2329\mathit{\text{value}}\u232a$ and ${\mathbf{k1}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{kp}}+1\ge {\mathbf{k1}}$.
On entry, ${\mathbf{ldc}}=\u2329\mathit{\text{value}}\u232a$ and ${\mathbf{k1}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{ldc}}\ge {\mathbf{k1}}$.
On entry, ${\mathbf{n}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{n}}\ge 1$.
On entry, one of the equations is of order less than $1$.
On entry, ${\mathbf{x1}}=\u2329\mathit{\text{value}}\u232a$ and ${\mathbf{x0}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{x1}}>{\mathbf{x0}}$.
 ${\mathbf{ifail}}=2$

On entry, ${\mathbf{liw}}=\u2329\mathit{\text{value}}\u232a$ and ${\mathbf{n}}\times {\mathbf{k1}}+2\times {\mathbf{n}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{liw}}\ge {\mathbf{n}}\times {\mathbf{k1}}+2\times {\mathbf{n}}$.
On entry, ${\mathbf{lw}}=\u2329\mathit{\text{value}}\u232a$ and $2\times {\mathbf{n}}\times \left({\mathbf{kp}}+1\right)\times \left({\mathbf{n}}\times {\mathbf{k1}}+1\right)+7\times {\mathbf{n}}\times {\mathbf{k1}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{lw}}\ge 2\times {\mathbf{n}}\times \left({\mathbf{kp}}+1\right)\times \left({\mathbf{n}}\times {\mathbf{k1}}+1\right)+7\times {\mathbf{n}}\times {\mathbf{k1}}$.
 ${\mathbf{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.
 ${\mathbf{ifail}}=4$

Iterative refinement in the least squares solution has failed to converge. The coefficient matrix is too illconditioned.
 ${\mathbf{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.
 ${\mathbf{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.
 ${\mathbf{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
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
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 implementationspecific information.
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 ${k}_{p}$ is equal to the number of coefficients ${k}_{1}$ minus the average number of boundary conditions
$\frac{1}{n}{\displaystyle \sum _{i=1}^{n}}{l}_{i}$, 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 ${k}_{1}$. 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 $\left[1,1\right]$.
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. In the example in
Section 10, the
$y$ variables are to be determined at the current iteration whilst the
$z$ variables correspond to the solution determined at the previous iteration, (or the initial approximation on the first iteration). 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
${y}_{1}=ax+b$ in the range
$\left({x}_{0},{x}_{1}\right)$, we set
$\mathrm{B}$, the array of coefficients,
 $\mathrm{B}\left(1,1\right)=a\times \left({x}_{0}+{x}_{1}\right)+2\times b$,
 $\mathrm{B}\left(1,2\right)=a\times \left({x}_{1}{x}_{0}\right)/2$,
 and the remainder of the entries to zero.
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. (See
Section 10.) 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
in the range
$\left(1,1\right)$, with
${y}_{1}=0$,
${y}_{2}=3$,
${y}_{2}^{\prime}=0$ at
$x=1$.
Suppose an approximate solution is
${z}_{1}$,
${z}_{2}$ such that
${y}_{1}\sim {z}_{1}$,
${y}_{2}\sim {z}_{2}$: then the first equation gives, on linearizing,
The starting approximation is taken to be
${z}_{1}=0$,
${z}_{2}=3$. In the program below, the array
$\mathrm{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)