hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_ode_bvp_shoot_genpar_algeq (d02sa)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_ode_bvp_shoot_genpar_algeq (d02sa) solves a two-point boundary value problem for a system of first-order ordinary differential equations with boundary conditions, combined with additional algebraic equations. It uses initial value techniques and a modified Newton iteration in a shooting and matching method.

Syntax

[p, pf, dp, swp, w, ifail] = d02sa(p, n1, pe, pf, e, dp, swp, icount, range, bc, fcn, eqn, constr, ymax, monit, prsol, 'm', m, 'n', n, 'npoint', npoint)
[p, pf, dp, swp, w, ifail] = nag_ode_bvp_shoot_genpar_algeq(p, n1, pe, pf, e, dp, swp, icount, range, bc, fcn, eqn, constr, ymax, monit, prsol, 'm', m, 'n', n, 'npoint', npoint)
Note: the interface to this routine has changed since earlier releases of the toolbox:
At Mark 22: npoint was made optional

Description

nag_ode_bvp_shoot_genpar_algeq (d02sa) solves a two-point boundary value problem for a system of n first-order ordinary differential equations with separated boundary conditions by determining certain unknown arguments p1,p2,,pm. (There may also be additional algebraic equations to be solved in the determination of the arguments and, if so, these equations are defined by eqn.) The arguments may be, but need not be, boundary values; they may include eigenvalues, arguments in the coefficients of the differential equations, coefficients in series expansions or asymptotic expansions for boundary values, the length of the range of definition of the system of differential equations, etc.
It is assumed that we have a system of n differential equations of the form
y = fx,y,p , (1)
where p = p1,p2,,pmT  is the vector of arguments, and that the derivative f is evaluated by fcn. Also, n1 of the equations are assumed to depend on p. For n1<n the n-n1 equations of the system are not involved in the matching process. These are the driving equations; they should be independent of p and of the solution of the other n1 equations. In numbering the equations in fcn and bc the driving equations must be put first (as they naturally occur in most applications). The range of definition [a,b] of the differential equations is defined by range and may depend on the arguments p1,p2,,pm (that is, on p). range must define the points x1,x2,,xnpoint, npoint2, which must satisfy
a=x1<x2<<xnpoint=b (2)
(or a similar relationship with all the inequalities reversed).
If npoint>2 the points x1,x2,,xnpoint can be used to break up the range of definition. Integration is restarted at each of these points. This means that the differential equations (1) can be defined differently in each sub-interval xi,xi+1 , for i=1,2,,npoint-1. Also, since initial and maximum integration step sizes can be supplied on each sub-interval (via the array swp), you can indicate parts of the range a,b where the solution yx may be difficult to obtain accurately and can take appropriate action.
The boundary conditions may also depend on the arguments and are applied at a=x1 and b=xnpoint. They are defined (in bc) in the form
ya=g1p,>yb=g2p. (3)
The boundary value problem is solved by determining the unknown arguments p by a shooting and matching technique. The differential equations are always integrated from a to b with initial values ya=g1p. The solution vector thus obtained at x=b is subtracted from the vector g2p to give the n1 residuals r1p, ignoring the first n-n1, driving equations. Because the direction of integration is always from a to b, it is unnecessary, in bc, to supply values for the first n-n1 boundary values at b, that is the first n-n1 components of g2 in (3). For n1<m then r1p. Together with the m-n1 equations defined by eqn,
r2p=0, (4)
these give a vector of residuals r, which at the solution, p, must satisfy
r1p r2p =0. (5)
These equations are solved by a pseudo-Newton iteration which uses a modified singular value decomposition of J= r p  when solving the linear equations which arise. The Jacobian J used in Newton's method is obtained by numerical differentiation. The arguments at each Newton iteration are accepted only if the norm D-1J~+r2 is much reduced from its previous value. Here J~+ is the pseudo-inverse, calculated from the singular value decomposition, of a modified version of the Jacobian J (J+ is actually the inverse of the Jacobian in well-conditioned cases). D is a diagonal matrix with
dii=maxpi,pfi (6)
where pf is an array of floor values.
See Deuflhard (1974) for further details of the variants of Newton's method used, Gay (1976) for the modification of the singular value decomposition and Gladwell (1979) for an overview of the method used.
Two facilities are provided to prevent the pseudo-Newton iteration running into difficulty. First, you are permitted to specify constraints on the values of the arguments p via a constr. These constraints are only used to prevent the Newton iteration using values for p which would violate them; that is, they are not used to determine the values of p. Secondly, you are permitted to specify a maximum value ymax for yx at all points in the range a,b. It is intended that this facility be used to prevent machine ‘overflow’ in the integrations of equation (1) due to poor choices of the arguments p which might arise during the Newton iteration. When using this facility, it is presumed that you have an estimate of the likely size of yx at all points xa,b. ymax should then be chosen rather larger (say by a factor of 10) than this estimate.
You are strongly advised to supply a monit (or to call the ‘default’ function nag_ode_bvp_shoot_genpar_algeq_sample_monit (d02hbx), see monit) to monitor the progress of the pseudo-Newton iteration. You can output the solution of the problem yx by supplying a suitable prsol (an example is given in Example of a function designed to output the solution at equally spaced points).
nag_ode_bvp_shoot_genpar_algeq (d02sa) is designed to try all possible options before admitting failure and returning to you. Provided the function can start the Newton iteration from the initial point p it will exhaust all the options available to it (though you can override this by specifying a maximum number of iterations to be taken). The fact that all its options have been exhausted is the only error exit from the iteration. Other error exits are possible, however, whilst setting up the Newton iteration and when computing the final solution.
If you require more background information about the solution of boundary value problems by shooting methods you are recommended to read the appropriate chapters of Hall and Watt (1976), and for a detailed description of nag_ode_bvp_shoot_genpar_algeq (d02sa) Gladwell (1979) is recommended.

References

Deuflhard P (1974) A modified Newton method for the solution of ill-conditioned systems of nonlinear equations with application to multiple shooting Numer. Math. 22 289–315
Gay D (1976) On modifying singular values to solve possibly singular systems of nonlinear equations Working Paper 125 Computer Research Centre, National Bureau for Economics and Management Science, Cambridge, MA
Gladwell I (1979) The development of the boundary value codes in the ordinary differential equations chapter of the NAG Library Codes for Boundary Value Problems in Ordinary Differential Equations. Lecture Notes in Computer Science (eds B Childs, M Scott, J W Daniel, E Denman and P Nelson) 76 Springer–Verlag
Hall G and Watt J M (ed.) (1976) Modern Numerical Methods for Ordinary Differential Equations Clarendon Press, Oxford

Parameters

Compulsory Input Parameters

1:     pm – double array
pi must be set to an estimate of the ith argument, pi, for i=1,2,,m.
2:     n1 int64int32nag_int scalar
n1, the number of differential equations active in the matching process. The active equations must be placed last in the numbering in fcn and bc. The first n-n1 equations are used as the driving equations.
Constraint: n1n, n1m and n1>0.
3:     pem – double array
pei, for i=1,2,,m, must be set to a positive value for use in the convergence test in the ith argument pi. See the description of pf for further details.
Constraint: pei>0.0, for i=1,2,,m.
4:     pfm – double array
pfi, for i=1,2,,m, should be set to a ‘floor’ value in the convergence test on the ith argument pi. If pfi0.0 on entry then it is set to the small positive value ε (where ε may in most cases be considered to be machine precision); otherwise it is used unchanged.
The Newton iteration is presumed to have converged if a full Newton step is taken (istate=1 in the specification of monit), the singular values of the Jacobian are not being significantly perturbed (also see monit) and if the Newton correction Ci satisfies
Cipei×maxpi,pfi,  i=1,2,,m,  
where pi is the current value of the ith argument. The values pfi are also used in determining the Newton iterates as discussed in Description, see equation (6).
5:     en – double array
Default: ei=10-5
Values for use in controlling the local error in the integration of the differential equations. If erri is an estimate of the local error in yi, for i=1,2,,n, then
err i ei × maxε,yi ,  
where ε may in most cases be considered to be machine precision.
Constraint: ei>0.0, for i=1,2,,n.
6:     dpm – double array
A value to be used in perturbing the argument pi in the numerical differentiation to estimate the Jacobian used in Newton's method. If dpi=0.0 on entry, an estimate is made internally by setting
dpi = ε × maxpfi,pi , (7)
where pi is the initial value of the argument supplied by you and ε may in most cases be considered to be machine precision. The estimate of the Jacobian, J, is made using forward differences, that is for each i, for i=1,2,,m, pi is perturbed to pi+dpi and the ith column of J is estimated as
rpi+dpi-rpi/dpi  
where the other components of p are unchanged (see (3) for the notation used). If this fails to produce a Jacobian with significant columns, backward differences are tried by perturbing pi to pi-dpi and if this also fails then central differences are used with pi perturbed to pi+10.0×dpi. If this also fails then the calculation of the Jacobian is abandoned. If the Jacobian has not previously been calculated then an error exit is taken. If an earlier estimate of the Jacobian is available then the current argument set, pi, for i=1,2,,m, is abandoned in favour of the last argument set from which useful progress was made and the singular values of the Jacobian used at the point are modified before proceeding with the Newton iteration. You are recommended to use the default value dpi=0.0 unless you have prior knowledge of a better choice. If any of the perturbations described are likely to lead to an unfortunate set of argument values then you should use constr to prevent such perturbations (all changes of arguments are checked by a call to constr).
7:     swpldswp6 – double array
ldswp, the first dimension of the array, must satisfy the constraint ldswpnpoint.
swpi1 must contain an estimate for an initial step size for integration across the ith sub-interval xi,xi+1 , for i=1,2,,npoint-1, (see range). swpi1 should have the same sign as xi+1-xi if it is nonzero. If swpi1=0.0, on entry, a default value for the initial step size is calculated internally. This is the recommended mode of entry.
swpi3 must contain a lower bound for the modulus of the step size on the ith sub-interval x i ,x i + 1 , for i=1,2,,npoint-1. If swpi3=0.0 on entry, a very small default value is used. By setting swpi3>0.0 but smaller than the expected step sizes (assuming you have some insight into the likely step sizes) expensive integrations with arguments p far from the solution can be avoided.
swpi2 must contain an upper bound on the modulus of the step size to be used in the integration on x i ,x i + 1 , for i=1,2,,npoint-1. If swpi2=0.0 on entry no bound is assumed. This is the recommended mode of entry unless the solution is expected to have important features which might be ‘missed’ in the integration if the step size were permitted to be chosen freely.
8:     icount int64int32nag_int scalar
An upper bound on the number of Newton iterations. If icount=0 on entry, no check on the number of iterations is made (this is the recommended mode of entry).
Constraint: icount0.
9:     range – function handle or string containing name of m-file
range must specify the break-points xi, for i=1,2,,npoint, which may depend on the arguments pj, for j=1,2,,m.
[x] = range(npoint, p, m)

Input Parameters

1:     npoint int64int32nag_int scalar
2 plus the number of break-points in a,b.
2:     pm – double array
The current estimate of the ith argument, for i=1,2,,m.
3:     m int64int32nag_int scalar
m, the number of arguments.

Output Parameters

1:     xnpoint – double array
The ith break-point, for i=1,2,,npoint. The sequence xi must be strictly monotonic, that is either
a=x1<x2<<xnpoint=b  
or
a=x1>x2>>xnpoint=b.  
10:   bc – function handle or string containing name of m-file
bc must place in g1 and g2 the boundary conditions at a and b respectively.
[g1, g2] = bc(p, m, n)

Input Parameters

1:     pm – double array
An estimate of the ith argument, pi, for i=1,2,,m.
2:     m int64int32nag_int scalar
m, the number of arguments.
3:     n int64int32nag_int scalar
n, the number of differential equations.

Output Parameters

1:     g1n – double array
The value of yia, for i=1,2,,n, (where this may be a known value or a function of the parameters pj, for j=1,2,,m).
2:     g2n – double array
The value of yib, for i=1,2,,n, (where these may be known values or functions of the parameters pj, for j=1,2,,m). If n>n1, so that there are some driving equations, then the first n-n1 values of g2 need not be set since they are never used.
11:   fcn – function handle or string containing name of m-file
fcn must evaluate the functions fi (i.e., the derivatives yi), for i=1,2,,n.
[f] = fcn(x, y, n, p, m, ii)

Input Parameters

1:     x – double scalar
x, the value of the argument.
2:     yn – double array
yi, for i=1,2,,n, the value of the argument.
3:     n int64int32nag_int scalar
n, the number of equations.
4:     pm – double array
The current estimate of the ith argument pi, for i=1,2,,m.
5:     m int64int32nag_int scalar
m, the number of arguments.
6:     ii int64int32nag_int scalar
Specifies the sub-interval xi,xi+1 on which the derivatives are to be evaluated.

Output Parameters

1:     fn – double array
The derivative of yi, for i=1,2,,n, evaluated at x. fi may depend upon the parameters pj, for j=1,2,,m. If there are any driving equations (see Description) then these must be numbered first in the ordering of the components of f.
12:   eqn – function handle or string containing name of m-file
eqn is used to describe the additional algebraic equations to be solved in the determination of the parameters, pi, for i=1,2,,m. If there are no additional algebraic equations (i.e., m=n1) then eqn is never called and the string nag_ode_bvp_shoot_genpar_algeq_dummy_eqn (d02hbz) should be used as the actual argument.
[e] = eqn(q, p, m)

Input Parameters

1:     q int64int32nag_int scalar
The number of algebraic equations, m-n1.
2:     pm – double array
The current estimate of the ith argument pi, for i=1,2,,m.
3:     m int64int32nag_int scalar
m, the number of arguments.

Output Parameters

1:     eq – double array
The vector of residuals, r2p, that is the amount by which the current estimates of the arguments fail to satisfy the algebraic equations.
13:   constr – function handle or string containing name of m-file
constr is used to prevent the pseudo-Newton iteration running into difficulty. constr should return the value true if the constraints are satisfied by the parameters p1,p2,,pm. Otherwise constr should return the value false. Usually the dummy function nag_ode_bvp_shoot_genpar_algeq_dummy_constr (d02hby), which returns the value true at all times, will suffice and in the first instance this is recommended as the actual argument.
[result] = constr(p, m)

Input Parameters

1:     pm – double array
An estimate of the ith argument, pi, for i=1,2,,m.
2:     m int64int32nag_int scalar
m, the number of arguments.

Output Parameters

1:     result – logical scalar
result=true if the constraints are satisfied by the parameters p.
14:   ymax – double scalar
A non-negative value which is used as a bound on all values yx where yx is the solution at any point x between x1 and xnpoint for the current arguments p1,p2,,pm. If this bound is exceeded the integration is terminated and the current arguments are rejected. Such a rejection will result in an error exit if it prevents the initial residual or Jacobian, or the final solution, being calculated. If ymax=0 on entry, no bound on the solution y is used; that is the integrations proceed without any checking on the size of y.
15:   monit – function handle or string containing name of m-file
monit enables you to monitor the values of various quantities during the calculation. It is called by nag_ode_bvp_shoot_genpar_algeq (d02sa) after every calculation of the norm d-1J~+r2 which determines the strategy of the Newton method, every time there is an internal error exit leading to a change of strategy, and before an error exit when calculating the initial Jacobian. string nag_ode_bvp_shoot_genpar_algeq_sample_monit (d02hbx)nag_file_set_unit_advisory (x04ab)
monit(istate, iflag, ifail1, p, m, f, pnorm, pnorm1, eps, d)

Input Parameters

1:     istate int64int32nag_int scalar
The state of the Newton iteration.
istate=0
The calculation of the residual, Jacobian and d-1J~+r2 are taking place.
istate=1 to 5
During the Newton iteration a factor of 2-istate+1 of the Newton step is being used to try to reduce the norm.
istate=6
The current Newton step has been rejected and the Jacobian is being re-calculated.
istate=-6 to -1
An internal error exit has caused the rejection of the current set of argument values, p. -istate is the value which istate would have taken if the error had not occurred.
istate=-7
An internal error exit has occurred when calculating the initial Jacobian.
2:     iflag int64int32nag_int scalar
Whether or not the Jacobian being used has been calculated at the beginning of the current iteration. If the Jacobian has been updated then iflag=1; otherwise iflag=2. The Jacobian is only calculated when convergence to the current argument values has been slow.
3:     ifail1 int64int32nag_int scalar
If -6istate-1, ifail1 specifies the ifail error number that would be produced were control returned to you. ifail1 is unspecified for values of istate outside this range.
4:     pm – double array
The current estimate of the ith argument pi, for i=1,2,,m.
5:     m int64int32nag_int scalar
m, the number of arguments.
6:     fm – double array
r, the residual corresponding to the current argument values, provided 1istate5 or istate=-7. f is unspecified for other values of istate.
7:     pnorm – double scalar
A quantity against which all reductions in norm are currently measured.
8:     pnorm1 – double scalar
p, the norm of the current arguments. It is set for 1istate5 and is undefined for other values of istate.
9:     eps – double scalar
Gives some indication of the convergence rate. It is the current singular value modification factor (see Gay (1976)). It is zero initially and whenever convergence is proceeding steadily. eps is ε3/8 or greater (where ε may in most cases be considered machine precision) when the singular values of J are approximately zero or when convergence is not being achieved. The larger the value of eps the worse the convergence rate. When eps becomes too large the Newton iteration is terminated.
10:   dm – double array
J, the singular values of the current modified Jacobian matrix. If dm is small relative to d1 for a number of Jacobians corresponding to different argument values then the computed results should be viewed with suspicion. It could be that the matching equations do not depend significantly on some argument (which could be due to a programming error in fcn, bc, range or eqn). Alternatively, the system of differential equations may be very ill-conditioned when viewed as an initial value problem, in which case nag_ode_bvp_shoot_genpar_algeq (d02sa) is unsuitable. This may also be indicated by some singular values being very large. These values of di, for i=1,2,,m, should not be changed.
16:   prsol – function handle or string containing name of m-file
prsol can be used to obtain values of the solution y at a selected point z by integration across the final range x1,x npoint . If no output is required nag_ode_bvp_shoot_genpar_algeq_dummy_prsol (d02hbw) can be used as the actual argument.
[z] = prsol(z, y, n)

Input Parameters

1:     z – double scalar
Contains x1 on the first call. On subsequent calls z contains its previous output value.
2:     yn – double array
The solution value yi, for i=1,2,,n, at z.
3:     n int64int32nag_int scalar
n, the total number of differential equations.

Output Parameters

1:     z – double scalar
The next point at which output is required. The new point must be nearer xnpoint than the old.
If z is set to a point outside x1,x npoint the process stops and control returns from nag_ode_bvp_shoot_genpar_algeq (d02sa) to the (sub)program from which nag_ode_bvp_shoot_genpar_algeq (d02sa) is called. Otherwise the next call to prsol is made by nag_ode_bvp_shoot_genpar_algeq (d02sa) at the point z, with solution values y1,y2,,yn at z contained in y. If z is set to xnpoint exactly, the final call to prsol is made with y1,y2,,yn as values of the solution at xnpoint produced by the integration. In general the solution values obtained at xnpoint from prsol will differ from the values obtained at this point by a call to bc. The difference between the two solutions is the residual r. You are reminded that the points x1,x2,,xnpoint are available in the locations swp14,swp24,,swpnpoint4 at all times.

Optional Input Parameters

1:     m int64int32nag_int scalar
Default: the dimension of the arrays p, pe, pf, dp. (An error is raised if these dimensions are not equal.)
m, the number of arguments.
Constraint: m>0.
2:     n int64int32nag_int scalar
Default: the dimension of the array e.
n, the total number of differential equations.
Constraint: n>0.
3:     npoint int64int32nag_int scalar
Default: the first dimension of the array swp.
2 plus the number of break-points in the range of definition of the system of differential equations (1).
Constraint: npoint2.

Output Parameters

1:     pm – double array
The corrected value for the ith argument, unless an error has occurred, when it contains the last calculated value of the argument.
2:     pfm – double array
The values actually used.
3:     dpm – double array
The values actually used.
4:     swpldswp6 – double array
swpi1 contains the initial step size used on the last integration on x i ,x i + 1 , for i=1,2,,npoint-1, (excluding integrations during the calculation of the Jacobian).
swpi2, for i=1,2,,npoint-1, is usually unchanged. If the maximum step size swpi2 is so small or the length of the range x i ,x i + 1 is so short that on the last integration the step size was not controlled in the main by the size of the error tolerances ei but by these other factors, then swpnpoint2 is set to the floating-point value of i if the problem last occurred in x i ,x i + 1 . Any results obtained when this value is returned as nonzero should be viewed with caution.
swpi3, for i=1,2,,npoint-1, are unchanged.
If an error exit with ifail=4, 5 or 6 (see Error Indicators and Warnings) occurs on the integration made from xi to xi+1 the floating-point value of i is returned in swpnpoint1. The actual point x x i ,x i + 1 where the error occurred is returned in swp15 (see also the specification of w). The floating-point value of npoint is returned in swpnpoint1 if the error exit is caused by a call to bc.
If an error exit occurs when estimating the Jacobian matrix (ifail=7, 8, 9, 10, 11 or 12, see Error Indicators and Warnings) and if argument pi was the cause of the failure then on exit swpnpoint1 contains the floating-point value of i.
swpi4 contains the point xi, for i=1,2,,npoint, used at the solution p or at the final values of p if an error occurred.
swp is also partly used as workspace.
5:     wldwsdw – double array
sdw=3×m+12+max11,m.
In the case of an error exit of the type where the point of failure is returned in swp15, the solution at this point of failure is returned in wi1, for i=1,2,,n.
Otherwise w is used for workspace.
6:     ifail int64int32nag_int scalar
ifail=0 unless the function detects an error (see Error Indicators and Warnings).

Error Indicators and Warnings

Errors or warnings detected by the function:
   ifail=1
One or more of the arguments n, n1, m, ldswp, npoint, icount, ldw, sdw, e, pe or ymax is incorrectly set.
   ifail=2
The constraints have been violated by the initial arguments.
   ifail=3
The condition x1<x2<<xnpoint (or x1>x2>>xnpoint) has been violated on a call to range with the initial arguments.
   ifail=4
In the integration from x1 to xnpoint with the initial or the final arguments, the step size was reduced too far for the integration to proceed. Consider reversing the order of the points x1,x2,,xnpoint. If this error exit still results, it is likely that nag_ode_bvp_shoot_genpar_algeq (d02sa) is not a suitable method for solving the problem, or the initial choice of arguments is very poor, or the accuracy requirement specified by ei, for i=1,2,,n, is too stringent.
   ifail=5
In the integration from x1 to xnpoint with the initial or final arguments, an initial step could not be found to start the integration on one of the intervals xi to xi+1. Consider reversing the order of the points. If this error exit still results it is likely that nag_ode_bvp_shoot_genpar_algeq (d02sa) is not a suitable function for solving the problem, or the initial choice of arguments is very poor, or the accuracy requirement specified by ei, for i=1,2,,n, is much too stringent.
   ifail=6
In the integration from x1 to xnpoint with the initial or final arguments, the solution exceeded ymax in magnitude (when ymax>0.0). It is likely that the initial choice of arguments was very poor or ymax was incorrectly set.
Note: on an error with ifail=4, 5 or 6 with the initial arguments, the interval in which failure occurs is contained in swpnpoint1. If a monit similar to the one in Example is being used then it is a simple matter to distinguish between errors using the initial and final arguments. None of the error exits ifail=4, 5 or 6 should occur on the final integration (when computing the solution) as this integration has already been performed previously with exactly the same arguments pi, for i=1,2,,m. Seek expert help if this error occurs.
   ifail=7
On calculating the initial approximation to the Jacobian, the constraints were violated.
   ifail=8
On perturbing the arguments when calculating the initial approximation to the Jacobian, the condition x1<x2<<xnpoint (or x1>x2>>xnpoint) is violated.
   ifail=9
On calculating the initial approximation to the Jacobian, the integration step size was reduced too far to make further progress (see ifail=4).
   ifail=10
On calculating the initial approximation to the Jacobian, the initial integration step size on some interval was too small (see ifail=5).
   ifail=11
On calculating the initial approximation to the Jacobian, the solution of the system of differential equations exceeded ymax in magnitude (when ymax>0.0).
Note: all the error exits ifail=7, 8, 9, 10 and 11 can be treated by reducing the size of some or all the elements of dp.
   ifail=12
On calculating the initial approximation to the Jacobian, a column of the Jacobian is found to be insignificant. This could be due to an element dpi being too small (but nonzero) or the solution having no dependence on one of the arguments (a programming error).
Note: on an error exit with ifail=7, 8, 9, 10, 11 or 12, if a perturbation of the argument pi is the cause of the error then swpnpoint1 will contain the floating-point value of i.
   ifail=13
After calculating the initial approximation to the Jacobian, the calculation of its singular value decomposition failed. It is likely that the error will never occur as it is usually associated with the Jacobian having multiple singular values. To remedy the error it should only be necessary to change the initial arguments. If the error persists it is likely that the problem has not been correctly formulated.
   ifail=14
The Newton iteration has failed to converge after exercising all its options. You are strongly recommended to monitor the progress of the iteration via monit. There are many possible reasons for the iteration not converging. Amongst the most likely are:
(a) there is no solution;
(b) the initial arguments are too far away from the correct arguments;
(c) the problem is too ill-conditioned as an initial value problem for Newton's method to choose suitable corrections;
(d) the accuracy requirements for convergence are too restrictive, that is some of the components of pe (and maybe pf) are too small – in this case the final value of this norm output via monit will usually be very small; or
(e) the initial arguments are so close to the solution arguments p that the Newton iteration cannot find improved arguments. The norm output by monit should be very small.
   ifail=15
The number of iterations permitted by icount has been exceeded (in the case when icount>0 on entry).
   ifail=16
   ifail=17
   ifail=18
   ifail=19
These indicate that there has been a serious error in an internal call. Check all function calls and array dimensions. Seek expert help.
   ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   ifail=-999
Dynamic memory allocation failed.

Accuracy

If the iteration converges, the accuracy to which the unknown arguments are determined is usually close to that specified by you. The accuracy of the solution (output via prsol) depends on the error tolerances ei, for i=1,2,,n. You are strongly recommended to vary all tolerances to check the accuracy of the arguments p and the solution y.

Further Comments

The time taken by nag_ode_bvp_shoot_genpar_algeq (d02sa) depends on the complexity of the system of differential equations and on the number of iterations required. In practice, the integration of the differential system (1) is usually by far the most costly process involved. The computing time for integrating the differential equations can sometimes depend critically on the quality of the initial estimates for the arguments p. If it seems that too much computing time is required and, in particular, if the values of the residuals (output in monit) are much larger than expected given your knowledge of the expected solution, then the coding of fcn, eqn, range and bc should be checked for errors. If no errors can be found then an independent attempt should be made to improve the initial estimates p.
In the case of an error exit in the integration of the differential system indicated by ifail=4, 5, 9 or 10 you are strongly recommended to perform trial integrations with nag_ode_ivp_rkts_onestep (d02pf) to determine the effects of changes of the local error tolerances and of changes to the initial choice of the arguments pi, for i=1,2,,m, (that is the initial choice of p).
It is possible that by following the advice given in Error Indicators and Warnings an error exit with ifail=7, 8, 9, 10 or 11 might be followed by one with ifail=12 (or vice-versa) where the advice given is the opposite. If you are unable to refine the choice of dpi, for i=1,2,,n, such that both these types of exits are avoided then the problem should be rescaled if possible or the method must be abandoned.
The choice of the ‘floor’ values pfi, for i=1,2,,m, may be critical in the convergence of the Newton iteration. For each value i, the initial choice of pi and the choice of pfi should not both be very small unless it is expected that the final argument pi will be very small and that it should be determined accurately in a relative sense.
For many problems it is critical that a good initial estimate be found for the arguments p or the iteration will not converge or may even break down with an error exit. There are many mathematical techniques which obtain good initial estimates for p in simple cases but which may fail to produce useful estimates in harder cases. If no such technique is available it is recommended that you try a continuation (homotopy) technique preferably based on a physical argument (e.g., the Reynolds or Prandtl number is often a suitable continuation argument). In a continuation method a sequence of problems is solved, one for each choice of the continuation argument, starting with the problem of interest. At each stage the arguments p calculated at earlier stages are used to compute a good initial estimate for the arguments at the current stage (see Hall and Watt (1976) for more details).

Example

This example intends to illustrate the use of the break-point and equation solving facilities of nag_ode_bvp_shoot_genpar_algeq (d02sa). Most of the facilities which are common to nag_ode_bvp_shoot_genpar_algeq (d02sa) and nag_ode_bvp_shoot_genpar (d02hb) are illustrated in the example in the specification of nag_ode_bvp_shoot_genpar (d02hb) (which should also be consulted).
The program solves a projectile problem in two media determining the position of change of media, p3, and the gravity and viscosity in the second medium (p2 represents gravity and p4 represents viscosity).
function d02sa_example


fprintf('d02sa example results\n\n');

% For communication with prsol.
global ykeep ncall xkeep;

% Initialize variables and arrays.
p   = [1.2; 0.032; 2.5;0.2];
n1  = int64(3);
pe  = [0.001; 0.001; 0.001; 0.001];
pf  = [1e-06; 1e-06; 1e-06; 1e-06];
e   = [1e-05; 1e-05; 1e-05];
dp  = [0; 0; 0; 0];
swp = zeros(3, 6);
icount = int64(0);
ymax   = 0;
ncall  = 0;
ykeep  = zeros(1,3);
xkeep  = zeros(1,1);

fprintf('   x        y(1)        y(2)        y(3)\n')

[p, pf, dp, swp, w, ifail] = ...
  d02sa(...
        p, n1, pe, pf, e, dp, swp, icount, @range, @bc, @fcn, ...
        @eqn, @constr, ymax, @monit, @prsol);

% Plot results.
fig1 = figure;
display_plot(xkeep,ykeep)


function z = prsol(z, y, n)
  % Obtains values for solution and stores them for plotting.

  % For communication with main routine.
  global ykeep ncall xkeep;
  ncall = ncall+1;
  fprintf(' %6.4f',z);
  xkeep(ncall,1) = z;
  fprintf('%10.4f  ', y(1:n));
  fprintf('\n');
  z = z+0.5;
  if (abs(z-5) < 0.25)
    z = 5;
  end
  ykeep(ncall,:) = y;

function x = range(npoint, p, m)
  % Specify the break points.
  x = zeros(npoint,1);
  x(1) = 0;
  x(2) = p(3);
  x(3) = 5;

function [g1, g2] = bc(p, m, n)
  % Specify boundary conditions.
  g1 = [0, 0.5, p(1)];
  g2 = [0, 0.45, -1.2];

function f = fcn(x, y, n, p, m, interval)
  % Evaluate derivative vector.
  f = zeros(n,1);
  f(1) = tan(y(3));
  if (interval == 1)
    f(2) = -0.032d0*tan(y(3))/y(2) - 0.02d0*y(2)/cos(y(3));
    f(3) = -0.032d0/y(2)^2;
  else
    f(2) = -p(2)*tan(y(3))/y(2) - p(4)*y(2)/cos(y(3));
    f(3) = -p(2)/y(2)^2;
  end

function eq = eqn(q,p,m)
  % Specify additional algebraic equations.
  eq = zeros(q,1);
  eq(1) = 0.02 - p(4) - 1.0d-5*p(3);

function result = constr(p,n)
  % Check constraints.
  result = true;
  for i=1:n
    if p(i) < 0
      result = false;
    end
  end
  if p(3) > 5
    result = false;
  end

function monit(istate, iflag, ifail1, p, m, f, pnorm, pnorm1, eps, d)
  % Allows monitoring of parameter values during solution (not used here).

function display_plot(xkeep,ykeep)
  % Plot the results.
  plot(xkeep, ykeep(:,1), '-+', ...
       xkeep, ykeep(:,2), '--x', ...
       xkeep, ykeep(:,3), ':*');
  % Add title.
  title('Projectile in Two Media Problem');
  % Label the axes.
  xlabel('x');
  ylabel('Solution');
  % Add a legend.
  legend('height','velocity','angle','Location','SouthWest');

  % Now get the range of the x and y values, and use them to make nice axes.
  xmin = min(xkeep);
  xmax = max(xkeep);
  ymin = round(min(min(ykeep))-1);
  ymax = round(max(max(ykeep))+1);
  axis([xmin xmax ymin ymax]);

  stem(xkeep, ykeep, ymin, ymax, 'determined interface');

function stem(x, y, ymin, ymax, label)
  % Find the x bin that the crossover point between y2 and y3 lies in.
  for i = 1:length(x)
    if y(i,2) > y(i,3)
      break
    end
  end
  % Use interpolation to find the crossover point more accurately.
  m(1:2) = (y(i,2:3) - y(i-1,2:3))/(x(i)-x(i-1));
  c(1:2) = y(i,2:3) - m(1:2)*x(i);
  xx = (c(2)-c(1))/(m(1)-m(2));
  hold on
  % Draw line, and add label.
  plot([xx,xx],[ymin,ymax],'k-s');
  text('Position', [xx-0.1,0.5], 'String', label, 'Rotation', 90.0)
d02sa example results

   x        y(1)        y(2)        y(3)
 0.0000    0.0000      0.5000      1.1753  
 0.5000    1.0881      0.4127      1.0977  
 1.0000    1.9501      0.3310      0.9802  
 1.5000    2.5768      0.2582      0.7918  
 2.0000    2.9606      0.2019      0.4796  
 2.5000    3.0958      0.1773      0.0245  
 3.0000    2.9861      0.1935     -0.4353  
 3.5000    2.6289      0.2409     -0.7679  
 4.0000    2.0181      0.3047     -0.9767  
 4.5000    1.1454      0.3759     -1.1099  
 5.0000   -0.0000      0.4500     -1.2000  
d02sa_fig1.png

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015