The routine may be called by the names d02haf or nagf_ode_bvp_shoot_bval.
d02haf solves a two-point boundary value problem for a system of ordinary differential equations in the range . The system is written in the form:
and the derivatives are evaluated by fcn. Initially, boundary values of the variables must be specified, some at and some at . You must supply estimates of the remaining boundary values (called parameters below); the subroutine corrects these by a form of Newton iteration. It also calculates the complete solution on an equispaced mesh if required.
Starting from the known and estimated values of at , the subroutine integrates the equations from to (using a Runge–Kutta–Merson method). The differences between the values of at from integration and those specified initially should be zero for the true solution. (These differences are called residuals below.) The subroutine uses a generalized Newton method to reduce the residuals to zero, by calculating corrections to the estimated boundary values. This process is repeated iteratively until convergence is obtained, or until the routine can no longer reduce the residuals. See Hall and Watt (1976) for a simple discussion of shooting and matching techniques.
Hall G and Watt J M (ed.) (1976) Modern Numerical Methods for Ordinary Differential Equations Clarendon Press, Oxford
1: – Real (Kind=nag_wp) arrayInput/Output
On entry: must be set to the known or estimated value of at and must be set to the known or estimated value of at , for .
On exit: the known values unaltered, and corrected values of the estimates, unless an error has occurred. If an error has occurred, u contains the known values and the latest values of the estimates.
2: – Real (Kind=nag_wp) arrayInput
On entry: must be set to if is a known value and to if is an estimated value, for and .
precisely of the must be set to , i.e., precisely of the must be known values, and these must not be all at or all at .
3: – IntegerInput
On entry: , the number of equations.
4: – Real (Kind=nag_wp)Input
On entry: , the initial point of the interval of integration.
5: – Real (Kind=nag_wp)Input
On entry: , the final point of the interval of integration.
6: – Real (Kind=nag_wp)Input
On entry: must be set to a small quantity suitable for:
(a)testing the local error in during integration,
(b)testing for the convergence of at ,
(c)calculating the perturbation in estimated boundary values for , which are used to obtain the approximate derivatives of the residuals for use in the Newton iteration.
You are advised to check your results by varying tol.
7: – Subroutine, supplied by the user.External Procedure
fcn must evaluate the functions
(i.e., the derivatives ), for , at a general point .
In the description of the arguments of d02haf below, denotes the actual value of n in the call of d02haf.
1: – Real (Kind=nag_wp)Input
On entry: , the value of the argument.
2: – Real (Kind=nag_wp) arrayInput
On entry: , for , the value of the argument.
3: – Real (Kind=nag_wp) arrayOutput
On exit: the values of
, for .
fcn must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which d02haf is called. Arguments denoted as Input must not be changed by this procedure.
Note:fcn should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by d02haf. If your code inadvertently does return any NaNs or infinities, d02haf is likely to produce unexpected results.
8: – Real (Kind=nag_wp) arrayOutput
On exit: the solution when .
9: – IntegerInput
On entry: a value which controls output.
The final solution is not evaluated.
The final values of
at interval are calculated and stored in the array soln by columns, starting with values at stored in , for .
10: – Real (Kind=nag_wp) arrayOutput
On exit: if , , or ,
, for , contains the solution at the point where the integration fails and the point of failure is returned in .
11: – IntegerInput
On entry: the second dimension of the array w as declared in the (sub)program from which d02haf is called.
12: – IntegerInput/Output
This routine uses an ifail input value codification that differs from the normal case to distinguish between errors and warnings (see Section 4 in the Introduction to the NAG Library FL Interface).
On entry: ifail must be set to one of the values below to set behaviour on detection of an error; these values have no effect when no error is detected. The behaviour relate to whether or not program execution is halted and whether or not messages are printed when an error or warning is detected.
For environments where it might be inappropriate to halt program execution when an error is detected, the value , , or is recommended. If the printing of messages is undesirable, then the value is recommended. Otherwise, the recommended value is . When the value , , or 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).
6Error 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, incorrect number of boundary values were flagged as known.
Number flagged as known: , but number should be .
On entry, .
On entry, .
On entry, .
Constraint: ; that is, .
On entry, .
On entry all left-hand boundary values were flagged as known.
On entry no left-hand boundary values were flagged as known.
In the integration with initial or final parameters, the step size was reduced too far for the integration to proceed. Either this routine is not a suitable method for solving the problem, or the initial choice of parameters is very poor.
In the integration with initial or final parameters, a suitable initial step could not be found. Either this routine is not suitable for solving the problem, or the initial choice of parameters is very poor.
An initial step-length could be found for integration to proceed with the current parameters.
The step-length required to calculate the Jacobian to sufficient accuracy is too small
The Jacobian has an insignificant column. Make sure that the solution vector depends on all the parameters.
An internal singular value decomposition has failed.
This error can be avoided by changing the initial parameter estimates.
The Newton iteration has failed to converge.
This can indicate a poor initial choice of parameters or a very difficult problem.
Consider varying elements of the parameter convergence control if the residuals are small; otherwise vary initial parameter estimates.
Internal error in calculating residual. Please contact NAG.
Internal error in calculating Jacobian. Please contact NAG.
Internal error in Newton method. Please contact NAG.
An unexpected error has been triggered by this routine. Please
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
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.
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.
If the process converges, the accuracy to which the unknown parameters are determined is usually close to that specified by you; the solution, if requested, may be determined to a required accuracy by varying tol.
8Parallelism and Performance
d02haf 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.
d02haf 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 d02haf depends on the complexity of the system, and on the number of iterations required. In practice, integration of the differential equations is by far the most costly process involved.
Wherever it occurs in the routine, the error argument tol is used in ‘mixed’ form; that is tol always occurs in expressions of the form . Though not ideal for every application, it is expected that this mixture of absolute and relative error testing will be adequate for most purposes.
You are strongly recommended to set ifail to obtain self-explanatory error messages, and also monitoring information about the course of the computation. You may select the unit numbers on which this output is to appear by calls of x04aaf (for error messages) or x04abf (for monitoring information) – see Section 10 for an example. Otherwise the default unit numbers will be used, as specified in the Users' Note. The monitoring information produced at each iteration includes the current parameter values, the residuals and -norms: a basic norm and a current norm. At each iteration the aim is to find parameter values which make the current norm less than the basic norm. Both these norms should tend to zero as should the residuals. (They would all be zero if the exact parameters were used as input.) For more details, you may consult the specification of d02saf, and especially the description of the argument monit there.
The computing time for integrating the differential equations can sometimes depend critically on the quality of the initial estimates. If it seems that too much computing time is required and, in particular, if the values of the residuals printed by the monitoring routine are much larger than the expected values of the solution at , then the coding of fcn should be checked for errors. If no errors can be found, an independent attempt should be made to improve the initial estimates. In practical problems it is not uncommon for the differential equation to have a singular point at one or both ends of the range. Suppose is a singular point; then the derivatives in (1) (in Section 3) cannot be evaluated at , usually because one or more of the expressions for give overflow. In such a case it is necessary for you to take a short distance away from the singularity, and to find values for at the new value of (e.g., use the first one or two terms of an analytical (power series) solution). You should experiment with the new position of ; if it is taken too close to the singular point, the derivatives will be inaccurate, and the routine may sometimes fail with or or, in extreme cases, with an overflow condition. A more general treatment of singular solutions is provided by the subroutine d02hbf.
Another difficulty which often arises in practice is the case when one end of the range, say, is at infinity. You must approximate the end point by taking a finite value for , which is obtained by estimating where the solution will reach its asymptotic state. The estimate can be checked by repeating the calculation with a larger value of . If is very large, and if the matching point is also at , the numerical solution may suffer a considerable loss of accuracy in integrating across the range, and the program may fail with or . (In the former case, solutions from all initial values at are tending to the same curve at infinity.) The simplest remedy is to try to solve the equations with a smaller value of , and then to increase in stages, using each solution to give boundary value estimates for the next calculation. For problems where some terms in the asymptotic form of the solution are known, d02hbf will be more successful.
If the unknown quantities are not boundary values, but are eigenvalues or the length of the range or some other parameters occurring in the differential equations, d02hbf may be used.
This example finds the angle at which a projectile must be fired for a given range.
The differential equations are:
with the following boundary conditions:
The remaining boundary conditions are estimated as:
We write , , . To check the accuracy of the results the problem is solved twice with and respectively. Note the call to x04abf before the call to d02haf.