naginterfaces.library.ode.bvp_shoot_genpar_algeq¶
- naginterfaces.library.ode.bvp_shoot_genpar_algeq(p, n, n1, pe, pf, dp, swp, icount, brkpts, bc, fcn, ymax, monlev, comm, e=None, eqn=None, constr=None, monit=None, prsol=None, data=None, io_manager=None)[source]¶
bvp_shoot_genpar_algeq
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.For full information please refer to the NAG Library document for d02sa
https://support.nag.com/numeric/nl/nagdoc_30.3/flhtml/d02/d02saf.html
- Parameters
- pfloat, array-like, shape
must be set to an estimate of the th argument, , for .
- nint
, the total number of differential equations.
- n1int
, the number of differential equations active in the matching process. The active equations must be placed last in the numbering in and . The first equations are used as the driving equations.
- pefloat, array-like, shape
, for , must be set to a positive value for use in the convergence test in the th argument . See the description of for further details.
- pffloat, array-like, shape
, for , should be set to a ‘floor’ value in the convergence test on the th argument . If 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 ( in the specification of ), the singular values of the Jacobian are not being significantly perturbed (also see ) and if the Newton correction satisfies
where is the current value of the th argument.
The values are also used in determining the Newton iterates as discussed in Notes, see equation (6).
- dpfloat, array-like, shape
A value to be used in perturbing the argument in the numerical differentiation to estimate the Jacobian used in Newton’s method. If on entry, an estimate is made internally by setting
where 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, , is made using forward differences, that is for each , for , is perturbed to and the th column of is estimated as
where the other components of are unchanged (see (3) for the notation used). If this fails to produce a Jacobian with significant columns, backward differences are tried by perturbing to and if this also fails then central differences are used with perturbed to . 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, , for , 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 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 to prevent such perturbations (all changes of arguments are checked by a call to ).
- swpfloat, array-like, shape
must contain an estimate for an initial step size for integration across the th sub-interval , for , (see ). should have the same sign as if it is nonzero. If , on entry, a default value for the initial step size is calculated internally. This is the recommended mode of entry.
must contain a lower bound for the modulus of the step size on the th sub-interval , for .
If on entry, a very small default value is used.
By setting but smaller than the expected step sizes (assuming you have some insight into the likely step sizes) expensive integrations with arguments far from the solution can be avoided.
must contain an upper bound on the modulus of the step size to be used in the integration on , for .
If 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.
- icountint
An upper bound on the number of Newton iterations. If on entry, no check on the number of iterations is made (this is the recommended mode of entry).
- brkptscallable x = brkpts(npoint, p, data=None)
must specify the break-points , for , which may depend on the arguments , for .
- Parameters
- npointint
plus the number of break-points in .
- pfloat, ndarray, shape
The current estimate of the th argument, for .
- dataarbitrary, optional, modifiable in place
User-communication data for callback functions.
- Returns
- xfloat, array-like, shape
The th break-point, for . The sequence must be strictly monotonic, that is either
or
- bccallable (g1, g2) = bc(p, n, data=None)
must place in and the boundary conditions at and respectively.
- Parameters
- pfloat, ndarray, shape
An estimate of the th argument, , for .
- nint
, the number of differential equations.
- dataarbitrary, optional, modifiable in place
User-communication data for callback functions.
- Returns
- g1float, array-like, shape
The value of , for , (where this may be a known value or a function of the parameters , for ).
- g2float, array-like, shape
The value of , for , (where these may be known values or functions of the parameters , for ). If , so that there are some driving equations, the first values of need not be set since they are never used.
- fcncallable f = fcn(x, y, p, i, data=None)
must evaluate the functions (i.e., the derivatives ), for .
- Parameters
- xfloat
, the value of the argument.
- yfloat, ndarray, shape
, for , the value of the argument.
- pfloat, ndarray, shape
The current estimate of the th argument , for .
- iint
Specifies the sub-interval on which the derivatives are to be evaluated.
- dataarbitrary, optional, modifiable in place
User-communication data for callback functions.
- Returns
- ffloat, array-like, shape
The derivative of , for , evaluated at . may depend upon the parameters , for . If there are any driving equations (see Notes) then these must be numbered first in the ordering of the components of .
- ymaxfloat
A non-negative value which is used as a bound on all values where is the solution at any point between and for the current arguments . 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 on entry, no bound on the solution is used; that is the integrations proceed without any checking on the size of .
- monlevint
Setting disables monitoring of the pseudo-Newton iteration. Setting enables this monitoring.
- commdict, communication object, modified in place
Communication structure.
On initial entry: need not be set.
- eNone or float, array-like, shape , optional
Note: if this argument is None then a default value will be used, determined as follows: .
Values for use in controlling the local error in the integration of the differential equations. If is an estimate of the local error in , for ,
where may in most cases be considered to be machine precision.
- eqnNone or callable e = eqn(q, p, data=None), optional
Note: if this argument is None then a NAG-supplied facility will be used.
is used to describe the additional algebraic equations to be solved in the determination of the parameters, , for .
If there are no additional algebraic equations (i.e., ) then is never called and may be None.
- Parameters
- qint
The number of algebraic equations, .
- pfloat, ndarray, shape
The current estimate of the th argument , for .
- dataarbitrary, optional, modifiable in place
User-communication data for callback functions.
- Returns
- efloat, array-like, shape
The vector of residuals, , that is the amount by which the current estimates of the arguments fail to satisfy the algebraic equations.
- constrNone or callable retval = constr(p, data=None), optional
Note: if this argument is None then a NAG-supplied facility will be used.
is used to prevent the pseudo-Newton iteration running into difficulty. should return the value if the constraints are satisfied by the parameters .
Otherwise should return the value . If None is supplied the function will act as if returns the value at all times, and in the first instance this is recommended as the actual argument.
- Parameters
- pfloat, ndarray, shape
An estimate of the th argument, , for .
- dataarbitrary, optional, modifiable in place
User-communication data for callback functions.
- Returns
- retvalbool
Must be if the constraints are satisfied by the parameters .
- monitNone or callable monit(istate, iflag, ifail1, p, f, pnorm, pnorm1, eps, d, data=None), optional
Note: if this argument is None then a NAG-supplied facility will be used.
enables you to monitor the values of various quantities during the calculation. If on entry no monitoring is performed and this argument is never referenced. Otherwise, if on entry, you may supply None, to use NAG-defined default monitoring, or you may supply your own custom monitoring function. The function is called by
bvp_shoot_genpar_algeq
after every calculation of the norm 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.- Parameters
- istateint
The state of the Newton iteration.
The calculation of the residual, Jacobian and are taking place.
to
During the Newton iteration a factor of of the Newton step is being used to try to reduce the norm.
The current Newton step has been rejected and the Jacobian is being re-calculated.
to
An internal error exit has caused the rejection of the current set of argument values, . is the value which would have taken if the error had not occurred.
An internal error exit has occurred when calculating the initial Jacobian.
- iflagint
Whether or not the Jacobian being used has been calculated at the beginning of the current iteration. If the Jacobian has been updated then ; otherwise . The Jacobian is only calculated when convergence to the current argument values has been slow.
- ifail1int
If , specifies the error number that would be produced were control returned to you. is unspecified for values of outside this range.
- pfloat, ndarray, shape
The current estimate of the th argument , for .
- ffloat, ndarray, shape
, the residual corresponding to the current argument values, provided or . is unspecified for other values of .
- pnormfloat
A quantity against which all reductions in norm are currently measured.
- pnorm1float
, the norm of the current arguments. It is set for and is undefined for other values of .
- epsfloat
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. is or greater (where may in most cases be considered machine precision) when the singular values of are approximately zero or when convergence is not being achieved. The larger the value of the worse the convergence rate. When becomes too large the Newton iteration is terminated.
- dfloat, ndarray, shape
, the singular values of the current modified Jacobian matrix. If is small relative to 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 , , or ). Alternatively, the system of differential equations may be very ill-conditioned when viewed as an initial value problem, in which case
bvp_shoot_genpar_algeq
is unsuitable. This may also be indicated by some singular values being very large. These values of , for , should not be changed.- dataarbitrary, optional, modifiable in place
User-communication data for callback functions.
- prsolNone or callable z = prsol(z, y, data=None), optional
Note: if this argument is None then a NAG-supplied facility will be used.
can be used to obtain values of the solution at a selected point by integration across the final range .
If no output is required None can be used as the actual argument.
- Parameters
- zfloat
Contains on the first call. On subsequent calls contains its previous output value.
- yfloat, ndarray, shape
The solution value , for , at .
- dataarbitrary, optional, modifiable in place
User-communication data for callback functions.
- Returns
- zfloat
The next point at which output is required. The new point must be nearer than the old.
If is set to a point outside the process stops and control returns from
bvp_shoot_genpar_algeq
to the (sub)program from whichbvp_shoot_genpar_algeq
is called.Otherwise the next call to is made by
bvp_shoot_genpar_algeq
at the point , with solution values at contained in .If is set to exactly, the final call to is made with as values of the solution at produced by the integration.
In general the solution values obtained at from will differ from the values obtained at this point by a call to .
The difference between the two solutions is the residual .
You are reminded that the points are available in the locations at all times.
- dataarbitrary, optional
User-communication data for callback functions.
- io_managerFileObjManager, optional
Manager for I/O in this routine.
- Returns
- pfloat, ndarray, shape
The corrected value for the th argument, unless an error has occurred, when it contains the last calculated value of the argument.
- pffloat, ndarray, shape
The values actually used.
- dpfloat, ndarray, shape
The values actually used.
- swpfloat, ndarray, shape
contains the initial step size used on the last integration on , for , (excluding integrations during the calculation of the Jacobian).
, for , is usually unchanged.
If the maximum step size is so small or the length of the range is so short that on the last integration the step size was not controlled in the main by the size of the error tolerances but by these other factors, is set to the floating-point value of if the problem last occurred in .
Any results obtained when this value is returned as nonzero should be viewed with caution.
, for , are unchanged.
If an error exit with = 4, 5 or 6 (see Exceptions) occurs on the integration made from to the floating-point value of is returned in .
The actual point where the error occurred is returned in (see also the specification of ).
The floating-point value of is returned in if the error exit is caused by a call to .
If an error exit occurs when estimating the Jacobian matrix ( = 7, 8, 9, 10, 11 or 12, see Exceptions) and if argument was the cause of the failure then on exit contains the floating-point value of .
contains the point , for , used at the solution or at the final values of if an error occurred.
is also partly used as workspace.
- wfloat, ndarray, shape
In the case of an error exit of the type where the point of failure is returned in , the solution at this point of failure is returned in , for .
Otherwise is used for workspace.
- Raises
- NagValueError
- (errno )
On entry, .
Constraint: or .
- (errno )
On entry, an element of the parameter convergence control array is zero or negative.
- (errno )
On entry an element of the local error control array is zero or negative.
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, and .
Constraint: .
- (errno )
On entry, and .
Constraint: .
- (errno )
On entry, .
Constraint: .
- (errno )
The constraints have been violated by the initial parameters.
- (errno )
The sequence of break-points is not strictly monotonic in their initial specification.
- (errno )
In the integration from first to last break-point with initial or final parameters, the step size was reduced too far for the integration to proceed. Consider reversing the order of break-points or relaxing the local error control. If this error exit still results, either this function is not a suitable method for solving the problem, or the initial choice of parameters is very poor.
- (errno )
In the integration from first to last break-point with initial or final parameters, a suitable initial step could not be found on one of the intervals. Consider reversing the order of break-points or relaxing the local error control. If this error exit still results, either this function is not suitable for solving the problem, or the initial choice of parameters is very poor.
- (errno )
During integration the solution exceeded in magnitude, where, on entry, .
- (errno )
On calculating the initial approximation to the Jacobian, the constraints were violated.
- (errno )
On perturbing the parameters when calculating the initial approximation to the Jacobian, the monotonicity condition on break-points is violated.
- (errno )
An initial step-length could be found for integration to proceed with the current parameters.
- (errno )
The step-length required to calculate the Jacobian to sufficient accuracy is too small.
- (errno )
On calculating the initial approximation to the Jacobian, the solution to the system of differential equations exceeded in magnitude, where, on entry, .
- (errno )
The Jacobian has an insignificant column. Make sure that the solution vector depends on all the parameters.
- (errno )
An internal singular value decomposition has failed. This error can be avoided by changing the initial parameter estimates.
- (errno )
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.
- (errno )
The number of iterations permitted by has been exceeded where this was set to a positive value on entry. .
- (errno )
Internal error in calculating Jacobian. Please contact NAG.
- (errno )
Internal error in calculating residual. Please contact NAG.
- (errno )
Internal error in integration. Please contact NAG.
- (errno )
Internal error in Newton method. Please contact NAG.
- Notes
No equivalent traditional C interface for this routine exists in the NAG Library.
bvp_shoot_genpar_algeq
solves a two-point boundary value problem for a system of first-order ordinary differential equations with separated boundary conditions by determining certain unknown arguments . (There may also be additional algebraic equations to be solved in the determination of the arguments and, if so, these equations are defined by .) 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 differential equations of the form
where is the vector of arguments, and that the derivative is evaluated by . Also, of the equations are assumed to depend on . For the equations of the system are not involved in the matching process. These are the driving equations; they should be independent of and of the solution of the other equations. In numbering the equations in and the driving equations must be put first (as they naturally occur in most applications). The range of definition [] of the differential equations is defined by and may depend on the arguments (that is, on ). must define the points , , which must satisfy
(or a similar relationship with all the inequalities reversed).
If the points 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 , for . Also, since initial and maximum integration step sizes can be supplied on each sub-interval (via the array ), you can indicate parts of the range where the solution may be difficult to obtain accurately and can take appropriate action.
The boundary conditions may also depend on the arguments and are applied at and . They are defined (in ) in the form
The boundary value problem is solved by determining the unknown arguments by a shooting and matching technique. The differential equations are always integrated from to with initial values . The solution vector thus obtained at is subtracted from the vector to give the residuals , ignoring the first , driving equations. Because the direction of integration is always from to , it is unnecessary, in , to supply values for the first boundary values at , that is the first components of in (3). For then . Together with the equations defined by ,
these give a vector of residuals , which at the solution, , must satisfy
These equations are solved by a pseudo-Newton iteration which uses a modified singular value decomposition of when solving the linear equations which arise. The Jacobian used in Newton’s method is obtained by numerical differentiation. The arguments at each Newton iteration are accepted only if the norm is much reduced from its previous value. Here is the pseudo-inverse, calculated from the singular value decomposition, of a modified version of the Jacobian ( is actually the inverse of the Jacobian in well-conditioned cases). is a diagonal matrix with
where 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 via a . These constraints are only used to prevent the Newton iteration using values for which would violate them; that is, they are not used to determine the values of . Secondly, you are permitted to specify a maximum value for at all points in the range . 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 which might arise during the Newton iteration. When using this facility, it is presumed that you have an estimate of the likely size of at all points . should then be chosen rather larger (say by a factor of ) than this estimate.
You are strongly advised to set to monitor the progress of the pseudo-Newton iteration. You can output the solution of the problem by supplying a suitable .
bvp_shoot_genpar_algeq
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 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 modules of Hall and Watt (1976), and for a detailed description of
bvp_shoot_genpar_algeq
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 module 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