NAG Library Routine Document
d02jaf (bvp_coll_nth)
1
Purpose
d02jaf solves a regular linear two-point boundary value problem for a single th-order ordinary differential equation by Chebyshev series using collocation and least squares.
2
Specification
Fortran Interface
Subroutine d02jaf ( |
n, cf, bc, x0, x1, k1, kp, c, w, lw, iw, ifail) |
Integer, Intent (In) | :: | n, k1, kp, lw | Integer, Intent (Inout) | :: | ifail | Integer, Intent (Out) | :: | iw(k1) | Real (Kind=nag_wp), External | :: | cf | Real (Kind=nag_wp), Intent (In) | :: | x0, x1 | Real (Kind=nag_wp), Intent (Out) | :: | c(k1), w(lw) | External | :: | bc |
|
C Header Interface
#include <nagmk26.h>
void |
d02jaf_ (const Integer *n, double (NAG_CALL *cf)(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[], double w[], const Integer *lw, Integer iw[], Integer *ifail) |
|
3
Description
d02jaf calculates the solution of a regular two-point boundary value problem for a single
th-order linear ordinary differential equation as a Chebyshev series in the interval
. The differential equation
is defined by
cf, and the boundary conditions at the points
and
are defined by
bc.
You specify the degree of Chebyshev series required,
, 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
.
e02akf can be used to evaluate the solution at any point on the interval
– 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: – IntegerInput
-
On entry: , the order of the differential equation.
Constraint:
.
- 2: – 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
at a given point
, where, for
,
is the coefficient of
in the equation, and
is the right-hand side.
The specification of
cf is:
Fortran Interface
Real (Kind=nag_wp) | :: | cf | Integer, Intent (In) | :: | j | Real (Kind=nag_wp), Intent (In) | :: | x |
|
C Header Interface
#include <nagmk26.h>
double |
cf (const Integer *j, const double *x) |
|
- 1: – IntegerInput
-
On entry: the index of the function to be evaluated.
- 2: – Real (Kind=nag_wp)Input
-
On entry: the point at which 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.
Note: cf should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by
d02jaf. If your code inadvertently
does return any NaNs or infinities,
d02jaf is likely to produce unexpected results.
- 3: – Subroutine, supplied by the user.External Procedure
-
bc defines the boundary conditions, each of which has the form
or
. 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
#include <nagmk26.h>
void |
bc (const Integer *i, Integer *j, double *rhs) |
|
- 1: – IntegerInput
-
On entry: the index of the boundary condition to be defined.
- 2: – IntegerOutput
-
On exit: must be set to
if the boundary condition is
, and to
if it is
.
j must not be set to the same value
for two different values of
i.
- 3: – Real (Kind=nag_wp)Output
-
On exit: must be set to the value .
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.
Note: bc should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by
d02jaf. If your code inadvertently
does return any NaNs or infinities,
d02jaf is likely to produce unexpected results.
- 4: – Real (Kind=nag_wp)Input
- 5: – Real (Kind=nag_wp)Input
-
On entry: the left- and right-hand boundaries, and , respectively.
Constraint:
.
- 6: – 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 ).
Constraint:
.
- 7: – IntegerInput
-
On entry: the number of collocation points to be used.
Constraint:
.
- 8: – Real (Kind=nag_wp) arrayOutput
-
On exit: the computed Chebyshev coefficients; that is, the computed solution is:
where
is the
th Chebyshev polynomial of the first kind, and
denotes that the first coefficient,
, is halved.
- 9: – Real (Kind=nag_wp) arrayWorkspace
- 10: – IntegerInput
-
On entry: the dimension of the array
w as declared in the (sub)program from which
d02jaf is called.
Constraint:
.
- 11: – Integer arrayWorkspace
-
- 12: – IntegerInput/Output
-
On entry:
ifail must be set to
,
. 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
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, if you are not familiar with this argument, the recommended value is
.
When the value is used it is essential to test the value of ifail on exit.
On exit:
unless the routine detects an error or a warning has been flagged (see
Section 6).
6
Error Indicators and Warnings
If on entry
or
, explanatory error messages are output on the current error message unit (as defined by
x04aaf).
Errors or warnings detected by the routine:
-
On entry, and .
Constraint: .
On entry, , and .
Constraint: .
On entry, .
Constraint: .
On entry, and .
Constraint: .
-
On entry, .
Constraint: ; that is, .
-
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.
-
Iterative refinement in the least squares solution has failed to converge. The coefficient matrix is too ill-conditioned.
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.
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.
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.
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 are chosen to be the extrema of the appropriate shifted Chebyshev polynomial. If , 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
. 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
.
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
with boundary conditions
We use
,
and
, and
and
, so that the different Chebyshev series may be compared. The solution for
and
is evaluated by
e02akf at nine equally spaced points over the interval
.
10.1
Program Text
Program Text (d02jafe.f90)
10.2
Program Data
Program Data (d02jafe.d)
10.3
Program Results
Program Results (d02jafe.r)