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.
The routine may be called by the names d02jbf or nagf_ode_bvp_coll_sys.
3Description
d02jbf calculates the solution of a regular two-point boundary value problem for a regular linear $n$th-order system of first-order ordinary differential equations as a Chebyshev series in the interval $({x}_{0},{x}_{1})$. The differential equation
$${y}^{\prime}=A\left(x\right)y+r\left(x\right)$$
is defined by cf, and the boundary conditions at the points ${x}_{0}$ and ${x}_{1}$ are defined by bc.
You specify the degree of Chebyshev series required, ${\mathbf{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 $(\mathrm{-1},1)$.
e02akf can be used to evaluate the components of the solution at any point on the interval $({x}_{0},{x}_{1})$. e02ahf followed by e02akf can be used to evaluate their derivatives.
4References
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
5Arguments
1: $\mathbf{n}$ – IntegerInput
On entry: $n$, the order of the system of differential equations.
Constraint:
${\mathbf{n}}\ge 1$.
2: $\mathbf{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 ${a}_{i,j}\left(x\right)$, of $A$, at a given point $x$, or of a right-hand side function ${r}_{i}\left(x\right)$ if ${\mathbf{j}}=0$.
On entry: indicate the function to be evaluated, namely ${a}_{i,j}\left(x\right)$ if $1\le {\mathbf{j}}\le n$, or ${r}_{i}\left(x\right)$ if ${\mathbf{j}}=0$. $1\le {\mathbf{i}}\le n$, $0\le {\mathbf{j}}\le n$.
3: $\mathbf{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: $\mathbf{bc}$ – Subroutine, supplied by the user.External Procedure
bc defines the $n$ boundary conditions, which have the form ${y}_{k}\left({x}_{0}\right)=s$ or ${y}_{k}\left({x}_{1}\right)=s$. The boundary conditions may be specified in any order.
On entry: the index of the boundary condition to be defined.
2: $\mathbf{j}$ – IntegerOutput
On exit: must be set to $-k$ if the $i$th boundary condition is ${y}_{k}\left({x}_{0}\right)=s$, or to $+k$ if it is ${y}_{k}\left({x}_{1}\right)=s$.
j must not be set to the same value $k$ for two different values of i.
3: $\mathbf{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: $\mathbf{x0}$ – Real (Kind=nag_wp)Input
5: $\mathbf{x1}$ – Real (Kind=nag_wp)Input
On entry: the left- and right-hand boundaries, ${x}_{0}$ and ${x}_{1}$, respectively.
Constraint:
${\mathbf{x1}}>{\mathbf{x0}}$.
6: $\mathbf{k1}$ – IntegerInput
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 ${\mathbf{k1}}-1$).
Constraint:
${\mathbf{k1}}\ge 2$.
7: $\mathbf{kp}$ – IntegerInput
On entry: the number of collocation points to be used.
Constraint:
${\mathbf{kp}}\ge {\mathbf{k1}}-1$.
8: $\mathbf{c}({\mathbf{ldc}},{\mathbf{n}})$ – Real (Kind=nag_wp) arrayOutput
On exit: 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 $i$th Chebyshev polynomial of the first kind, and ${\sum}^{\prime}$ denotes that the first coefficient, ${\mathbf{c}}(1,k)$, is halved.
9: $\mathbf{ldc}$ – IntegerInput
On entry: the first dimension of the array c as declared in the (sub)program from which d02jbf is called.
Constraint:
${\mathbf{ldc}}\ge {\mathbf{k1}}$.
10: $\mathbf{w}\left({\mathbf{lw}}\right)$ – Real (Kind=nag_wp) arrayWorkspace
11: $\mathbf{lw}$ – IntegerInput
On entry: the dimension of the array w as declared in the (sub)program from which d02jbf is called.
On entry: ifail must be set to $0$, $\mathrm{-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 $\mathrm{-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 $\mathrm{-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 $-\mathbf{1}$ 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).
6Error Indicators and Warnings
If on entry ${\mathbf{ifail}}=0$ or $\mathrm{-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, ${\mathbf{k1}}=\u27e8\mathit{\text{value}}\u27e9$.
Constraint: ${\mathbf{k1}}\ge 2$.
On entry, ${\mathbf{kp}}=\u27e8\mathit{\text{value}}\u27e9$ and ${\mathbf{k1}}=\u27e8\mathit{\text{value}}\u27e9$.
Constraint: ${\mathbf{kp}}+1\ge {\mathbf{k1}}$.
On entry, ${\mathbf{n}}=\u27e8\mathit{\text{value}}\u27e9$.
Constraint: ${\mathbf{n}}\ge 1$.
On entry, ${\mathbf{x1}}=\u27e8\mathit{\text{value}}\u27e9$ and ${\mathbf{x0}}=\u27e8\mathit{\text{value}}\u27e9$.
Constraint: ${\mathbf{x1}}>{\mathbf{x0}}$.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{liw}}=\u27e8\mathit{\text{value}}\u27e9$.
Constraint: ${\mathbf{liw}}\ge {\mathbf{n}}\times {\mathbf{k1}}+2\times {\mathbf{n}}$; that is, $\u27e8\mathit{\text{value}}\u27e9$.
On entry, ${\mathbf{lw}}=\u27e8\mathit{\text{value}}\u27e9$.
Constraint: ${\mathbf{lw}}\ge 2\times {\mathbf{n}}\times ({\mathbf{kp}}+1)\times ({\mathbf{n}}\times {\mathbf{k1}}+1)+7\times {\mathbf{n}}\times {\mathbf{k1}}$; that is, $\u27e8\mathit{\text{value}}\u27e9$.
${\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 ill-conditioned.
${\mathbf{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.
${\mathbf{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.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.
7Accuracy
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).
8Parallelism 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.
9Further 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 $({x}_{0},{x}_{1})$ are chosen to be the extrema of the appropriate shifted Chebyshev polynomial. If ${\mathbf{kp}}={\mathbf{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 ${\mathbf{kp}}\gg {\mathbf{k1}}-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 $(\mathrm{-1},1)$.
Linear systems of high-order equations in their original form, singular problems, and, indirectly, nonlinear problems can be solved using d02tgf.
for solution by d02jbf and the boundary conditions are written
$${y}_{1}(-1)={y}_{1}\left(1\right)=0\text{.}$$
We use ${\mathbf{k1}}=4$, $6$ and $8$, and ${\mathbf{kp}}=10$ and $15$, so that the different Chebyshev series may be compared. The solution for ${\mathbf{k1}}=8$ and ${\mathbf{kp}}=15$ is evaluated by e02akf at nine equally spaced points over the interval $(\mathrm{-1},1)$.