Integer type:** int32**** int64**** nag_int** show int32 show int32 show int64 show int64 show nag_int show nag_int

nag_ode_ivp_2nd_rkn_interp (d02lz) interpolates components of the solution of a non-stiff system of second-order differential equations from information provided by the integrator nag_ode_ivp_2nd_rkn (d02la), when the low-order method has been used.

Mark 22: lrwork has been removed from the interface

.nag_ode_ivp_2nd_rkn_interp (d02lz) evaluates the first nwant${\mathbf{nwant}}$ ( ≤ neq$\text{}\le {\mathbf{neq}}$) components of the solution of a non-stiff system of second-order ordinary differential equations at any point using a special Runge–Kutta–Nystrom formula (see Dormand and Prince (1986)) and information generated by nag_ode_ivp_2nd_rkn (d02la) when the low-order method has been used. This information must be presented unchanged to nag_ode_ivp_2nd_rkn_interp (d02lz). nag_ode_ivp_2nd_rkn_interp (d02lz) should not normally be used to extrapolate outside the range of the values from nag_ode_ivp_2nd_rkn (d02la).

Dormand J R and Prince P J (1986) Runge–Kutta–Nystrom triples *Mathematical Report TP-CS-86-05* Teesside Polytechnic

- 1: t – double scalar
- t$t$, the current value at which the solution and its derivative have been computed (as returned in parameter t on output from nag_ode_ivp_2nd_rkn (d02la)).
- 2: y(neq) – double array
- The i$\mathit{i}$th component of the solution at t$t$, for i = 1,2, … ,neq$\mathit{i}=1,2,\dots ,{\mathbf{neq}}$, as returned from nag_ode_ivp_2nd_rkn (d02la).
- 3: yp(neq) – double array
- The i$\mathit{i}$th component of the derivative at t$t$, for i = 1,2, … ,neq$\mathit{i}=1,2,\dots ,{\mathbf{neq}}$, as returned from nag_ode_ivp_2nd_rkn (d02la).
- 4: nwant – int64int32nag_int scalar
- 5: twant – double scalar
- The point at which components of the solution and derivative are to be evaluated. twant should not normally be an extrapolation point, that is twant should satisfy or if integration is proceeding in the negative direction where told is the previous integration point which is held in an element of the array rwork and is, to within rounding, t − hused${\mathbf{t}}-{\mathbf{hused}}$. (hused is given by nag_ode_ivp_2nd_rkn_diag (d02ly).) Extrapolation is permitted but not recommended, and ifail = 2${\mathbf{ifail}}={\mathbf{2}}$ is returned whenever extrapolation is attempted.
- 6: rwork(lrwork) – double array
- This
**must**be the same parameter rwork as supplied to nag_ode_ivp_2nd_rkn (d02la). It is used to pass information from nag_ode_ivp_2nd_rkn (d02la) to nag_ode_ivp_2nd_rkn_interp (d02lz) and therefore the contents of this array**must****not**be changed before calling nag_ode_ivp_2nd_rkn_interp (d02lz).

- 1: neq – int64int32nag_int scalar
- The number of second-order ordinary differential equations being solved by nag_ode_ivp_2nd_rkn (d02la). It must contain the same value as the parameter neq in a prior call to nag_ode_ivp_2nd_rkn (d02la).

- lrwork

- 1: ywant(nwant) – double array
- 2: ypwant(nwant) – double array
- 3: ifail – int64int32nag_int scalar
- ifail = 0${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

Errors or warnings detected by the function:

Cases prefixed with `W` are classified as warnings and
do not generate an error of type NAG:error_*n*. See nag_issue_warnings.

- Illegal input detected, i.e., one of the following conditions:
– nag_ode_ivp_2nd_rkn (d02la) has not been called; – one or both of the parameters neq and lrwork does not match the corresponding parameter supplied to the setup function nag_ode_ivp_2nd_rkn_setup (d02lx); – no integration steps have been taken since the last call to nag_ode_ivp_2nd_rkn_setup (d02lx) with start = true${\mathbf{start}}=\mathbf{true}$; – nwant < 1${\mathbf{nwant}}<1$ or nwant > neq${\mathbf{nwant}}>{\mathbf{neq}}$. This error exit can be caused if elements of rwork have been overwritten.

`W`ifail = 2${\mathbf{ifail}}=2$- nag_ode_ivp_2nd_rkn_interp (d02lz) has been called for extrapolation. The values of the solution and its derivative at twant have been calculated and placed in ywant and ypwant before returning with this error number (see Section [Accuracy]).

- nag_ode_ivp_2nd_rkn (d02la) last used the high order method to integrate the system of differential equations. Interpolation is not permitted with this method.

The error in interpolation is of a similar order to the error arising from the integration using nag_ode_ivp_2nd_rkn (d02la) with the lower order method.

The same order of accuracy can be expected when extrapolating using nag_ode_ivp_2nd_rkn_interp (d02lz). However, the actual error in extrapolation will, in general, be much larger than for interpolation.

When interpolation for only a few components is required then it is more efficient to order the components of interest so that they are numbered first.

Open in the MATLAB editor: nag_ode_ivp_2nd_rkn_interp_example

function nag_ode_ivp_2nd_rkn_interp_examplet = 0; tend = 20; y = [0.5; 0]; yp = [0; 1.732050807568877]; ydp = zeros(2, 1); rwork = zeros(56,1); twant = 2; tnext = 2; nwant = int64(2); [startOut, rwork, ifail] = ... nag_ode_ivp_2nd_rkn_setup(0, 1e-4, zeros(2,1), zeros(2,1), int64(0), true, true, false, rwork); fprintf('\n T Y(1) Y(2)\n'); fprintf('%4.1f %10.5f %10.5f\n', t, y(1), y(2)); while (t < tend && ifail == 0) [t, y, yp, ydp, rwork, ifail] = nag_ode_ivp_2nd_rkn(@fcn, t, tend, y, yp, ydp, rwork); while (tnext <= t && ifail == 0) [ywant, ypwant, ifail] = nag_ode_ivp_2nd_rkn_interp(t, y, yp, nwant, tnext, rwork); fprintf('%4.1f %10.5f %10.5f\n', tnext, ywant(1), ywant(2)); tnext = tnext + 2; end end if (ifail == 0) [hnext, hused, hstart, nsucc, nfail, natt, thres, thresp, ifail] = ... nag_ode_ivp_2nd_rkn_diag(nwant, rwork); fprintf('\n Number of successful steps = %d\n', nsucc); fprintf(' Number of failed steps = %d\n', nfail); endfunction ydp = fcn(neq, t, y)% Evaluate second derivatives. r = sqrt(y(1)^2+y(2)^2)^3; f = zeros(2,1); ydp(1) = -y(1)/r; ydp(2) = -y(2)/r;

T Y(1) Y(2) 0.0 0.50000 0.00000 2.0 -1.20573 0.61357 4.0 -1.33476 -0.47685 6.0 0.35748 -0.44558 8.0 -1.03762 0.73022 10.0 -1.42617 -0.32658 12.0 0.05515 -0.72032 14.0 -0.82880 0.81788 16.0 -1.48103 -0.16788 18.0 -0.26719 -0.84223 20.0 -0.57803 0.86339 Number of successful steps = 108 Number of failed steps = 16

Open in the MATLAB editor: d02lz_example

function d02lz_examplet = 0; tend = 20; y = [0.5; 0]; yp = [0; 1.732050807568877]; ydp = zeros(2, 1); rwork = zeros(56,1); twant = 2; tnext = 2; nwant = int64(2); [startOut, rwork, ifail] = ... d02lx(0, 1e-4, zeros(2,1), zeros(2,1), int64(0), true, true, false, rwork); fprintf('\n T Y(1) Y(2)\n'); fprintf('%4.1f %10.5f %10.5f\n', t, y(1), y(2)); while (t < tend && ifail == 0) [t, y, yp, ydp, rwork, ifail] = d02la(@fcn, t, tend, y, yp, ydp, rwork); while (tnext <= t && ifail == 0) [ywant, ypwant, ifail] = d02lz(t, y, yp, nwant, tnext, rwork); fprintf('%4.1f %10.5f %10.5f\n', tnext, ywant(1), ywant(2)); tnext = tnext + 2; end end if (ifail == 0) [hnext, hused, hstart, nsucc, nfail, natt, thres, thresp, ifail] = ... d02ly(nwant, rwork); fprintf('\n Number of successful steps = %d\n', nsucc); fprintf(' Number of failed steps = %d\n', nfail); endfunction ydp = fcn(neq, t, y)% Evaluate second derivatives. r = sqrt(y(1)^2+y(2)^2)^3; f = zeros(2,1); ydp(1) = -y(1)/r; ydp(2) = -y(2)/r;

T Y(1) Y(2) 0.0 0.50000 0.00000 2.0 -1.20573 0.61357 4.0 -1.33476 -0.47685 6.0 0.35748 -0.44558 8.0 -1.03762 0.73022 10.0 -1.42617 -0.32658 12.0 0.05515 -0.72032 14.0 -0.82880 0.81788 16.0 -1.48103 -0.16788 18.0 -0.26719 -0.84223 20.0 -0.57803 0.86339 Number of successful steps = 108 Number of failed steps = 16

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