XLPack 7.0
XLPack Numerical Library (Excel VBA) Reference Manual
Loading...
Searching...
No Matches

◆ Dopn64_r()

Sub Dopn64_r ( N As  Long,
T As  Double,
Y() As  Double,
Yp() As  Double,
Tout As  Double,
Tend As  Double,
RTol() As  Double,
ATol() As  Double,
Mode As  Long,
Info As  Long,
TT As  Double,
YY() As  Double,
YYpp() As  Double,
IRev As  Long,
Optional Neval As  Long,
Optional Nstep As  Long,
Optional Naccept As  Long,
Optional Nreject As  Long,
Optional MaxIter As  Long = 0,
Optional ErrCntl As  Long = 0,
Optional Cnt As  Long = 0,
Optional Hinit As  Double = 0,
Optional Hmax As  Double = 0,
Optional Fac1 As  Double = 0,
Optional Fac2 As  Double = 0,
Optional Safe As  Double = 0 
)

Initial value problem of ordinary differential equations (6(4)-th order Runge-Kutta-Nystrom method) (for second order differential equations) (Reverse communication version)

Purpose
This program integrates a system of second order ordinary differential equations of the form
d2y/dt2 = f2(t, y), y = y0, y' = y'0 at t = t0
where y and y' are the n vectors and the system consists of n equations. t0, y0 and y'0 are the given initial values of t, y and y', respectively.
This program is based on the Runge-Kutta-Nystroem method of order 6(4). See for details of coefficients (RKN6(4)6FM) and interpolant for dense output in the references (1) and (2), respectively.
Parameters
[in]NNumber of differential equations. (N >= 1)
[in,out]TIndependent variable t. This program integrates from the initial value of t to Tend. Depending on the setting of Mode, this program may return at Tout or every successful step to provide an intermediate result. [in] An initial value of t (t0).
[out] T = Tend if the integration has been completed. Or T = Tout or T of the latest step depending on Mode in the case of intermediate return.
[in,out]Y()Array Y(LY - 1) (LY >= N)
Dependent variable y.
[in] Initial value of y (y0) at initial t (t0).
[out] The value of y (computed numerical solution) at t = T.
[in,out]Yp()Array Yp(LYp - 1) (LYp >= N)
y', derivatives of y.
[in] Initial values of derivtive y' (y'0) at initial t (t0).
[out] The value of y' (computed numerical solution) at t = T.
[in]ToutSet Tout to the point (t) at which an intermediate result is desired in mode = 2 or 3. Tout is not referenced in Mode = 0 or 1.
In Mode 2 or 3, y at Tout is computed and returned with Info = 2 or 3 respectively. To continue the integration to get result at new Tout, it is possible to call this program again with new Tout and without changing other variables including Info.
T < Tout <= Tend is required. However, if the integration is in backward direction, Tend <= Tout < T is required. If Tend is reached before Tout, the integration is terminated immediately and T = Tend and Info = 0 is returned.
[in]TendThe point at which an integration is completed. If Tend is reached, the integration is terminated and T = Tend and Info = 0 is returned. The integration is possible for both forward (Tend > T) and backward (Tend < T) direction.
[in]Rtol()Array Rtol(LRtol - 1) (LRtol >= 1) (all elements of Rtol() >= 0)
The relative error tolerance(s) to specify how accurately compute the solution. This parameter may be a scalar or an array according to the values of LRtol and LAtol (Scalar if LRtol < N or LAtol < N, array if LRtol >= N and LAtol >= N).
Rtol is used together with Atol in a local error test at each step. The integration is performed using step sizes which are automatically selected so as to achieve the following criteria.
Scalar case (i = 0 to N - 1):
(local error) <= max(Rtol(0)*Abs(Y(i)) + Atol(0), Rtol(0)*Abs(Yp(i)) + Atol(0)) (if ErrCntl = 0)
(local error) <= Rtol(0)*Abs(Y(i)) + Atol(0) (if ErrCntl = 1)
Both Rtol(0) and Atol(0) must not be 0 at the same time.
Array case (i = 0 to N - 1):
(local error) <= max(Rtol(i)*Abs(Y(i)) + Atol(i), Rtol(i)*Abs(Yp(i)) + Atol(i)) (if ErrCntl = 0)
(local error) <= Rtol(i)*Abs(Y(i)) + Atol(i) (if ErrCntl = 1)
Both Rtol(i) and Atol(i) must not be 0 at the same time.
[in]Atol()Array Atol(LAtol - 1) (LAtol >= 1) (all elements of Atol() >= 0)
The absolute error tolerance(s) to specify how accurately compute the solution. This parameter may be a scalar or an array according to the values of LRtol and LAtol (Scalar if LRtol < N or LAtol < N, array if LRtol >= N and LAtol >= N).
Atol is used together with Rtol in a local error test at each step (Refer to Rtol above).
[in]ModeMode of operation.
This program integrates from t0 to Tend. Four modes of operation are provided depending on the timing of returning imtermediate results. When Tend is reached, the integration is terminated and Info = 0 is returned in any of four modes. = 0: Not return until Tend. Tout is not referenced.
= 1: Returns at every successful step (Info = 1 is returned). Tout is not referenced. The end point of the last step is returned in T. In the final step, the step size is adjusted to fit into Tend.
= 2: Returns at Tout during the ingegration to provide an intermediate result (T = Tout and Info = 2 are returned). To continue the integration to get result at new Tout, it is possible to call this program again with new Tout. In the final step, the step size is adjusted to fit into Tout.
= 3: Returns at Tout during the ingegration to provide an intermediate result (T = Tout and Info = 3 are returned). To continue the integration to get result at new Tout, it is possible to call this program again with new Tout. Different from Mode = 2, the value of Y() at Tout is computed by interpolation, and the step size is not adjusted even in the last step before Tout. The steps through integration are same with those of Mode = 1.
[in,out]Info[in] Control code.
= 0: Set Info = 0 on the initial call to start new problem. All variables will be initialized and the computation will begin.
= 1, 2, 3: When returned with Info = 1, 2 or 3, it is possible to call this program again with new Tout and without changing Info to continue the integration.
[out] Return code.
= 0: Successful exit. Integration to Tend completed.
< 0: The (-Info)-th argument is invalid.
= 1: Returned to provide intermediate result in Mode = 1. It is possible to call this program again to forward to the next step.
= 2: Returned at T = Tout to provide intermediate result in Mode = 2. It is possible to call this program again with new Tout.
= 3: Returned at T = Tout to provide intermediate result in Mode = 3. It is possible to call this program again with new Tout.
= 11: (Error) Maximum number of steps exceeded.
= 12: (Error) Step size becomes too small.
[out]TTIRev = 1: Refer to YYpp().
[out]YY()Array YY(LYY - 1) (LYY >= N)
IRev = 1: Refer to YYpp().
[in]YYpp()Array YYpp(LYYpp - 1) (LYYpp >= N)
IRev = 1: Compute second derivatives at given T = TT and Y = YY(), d2y/dt2 = f2(t, y), and store in YYpp() in the next call.
[in,out]IRevControl variable for reverse communication.
[in] Before first call, IRev should be initialized to zero. On succeeding calls, IRev should not be altered.
[out] If IRev is not zero, complete the following tasks and call this program again without changing IRev.
= 0: Computation finished. Check return code in Info.
= 1: Computed second derivatives at T = TT and Y = YY() should be stored in YYpp(). Do not alter any variables other than YYpp().
[out]Neval(Optional)
Number of function evaluations.
[out]Nstep(Optional)
Number of all computed steps.
[out]Naccept(Optional)
Number of accepted steps.
[out]Nreject(Optional)
Number of rejected steps.
[in]Maxiter(Optional)
Maximum number of allowed steps. (default = 10000)
[in]ErrCntl(Optional)
Specifies how determine the acceptance of the step. (default = 0)
= 0: Determine the acceptance of the step using the estimated errors of both y and y'.
= 1: Determine the acceptance of the step using the estimated error of y only.
[in]Cnt(Optional)
Specifies when counters (Neval, Nstep, Naccept and Nreject) are reset to zero. (default = 0)
= 0: Reset if Info = 0.
= 1: Do not reset even if Info = 0.
[in]Hinit(Optional)
Initial step size. (default = estimated by the program)
[in]Hmax(Optional)
Maximaum step size. (default = Abs(Tend - T))
[in]Fac1,Fac2(Optional)
Parameters for step size selection. (default: Fac1 = 0.2, Fac2 = 10)
The new step size is chosen subject to the restriction Fac1 <= Hnew/Hold <= Fac2.
[in]Safe(Optional)
The safety factor in step size prediction. (0.0001 < Safe < 1) (default = 0.9)
References
(1) J. R. Dormand, M. E. A. El-Mikkawy, P. J. Prince, "Families of Runge-Kutta-Nystrom Formulae", IMA J. of Numerical Analysis, 7, 235-250 (1987).
(2) J. R. Dormand, P. J. Prince "Runge-Kutta-Nystrom Triples", Comput. Math. Applic. Vol. 13, No. 12, 937-949 (1987).
Example Program
Solve the following initial value problem of ordinary differential equations.
y1'' = -y1/R
y2'' = -y2/R
where R = (y1^2 + y2^2)^(3/2)/(π/4)^2
(y1 = 0.75, y2 = 0, y1' = 0, y2' = (π/4)√(1.25/0.75) at t = 0)
Sub F2(N As Long, T As Double, Y() As Double, Yp2() As Double)
Dim R As Double
R = (Y(0) ^ 2 + Y(1) ^ 2) ^ (3 / 2) / Atn(1) ^ 2
Yp2(0) = -Y(0) / R
Yp2(1) = -Y(1) / R
End Sub
Sub Ex_Dopn64_r()
Const N = 2
Dim T As Double, Y(N - 1) As Double, Yp(N - 1) As Double, Tend As Double, Tout As Double
Dim RTol(0) As Double, ATol(0) As Double, Mode As Long, Neval As Long, Info As Long
Dim TT As Double, YY(N - 1) As Double, YYpp(N - 1) As Double, IRev As Long
RTol(0) = 0.0000000001 '1.0e-10
ATol(0) = RTol(0)
Mode = 2
T = 0: Y(0) = 0.75: Y(1) = 0: Yp(0) = 0: Yp(1) = Atn(1) * Sqr(1.25 / 0.75)
Tend = 12
Info = 0
Do
Tout = T + 1
IRev = 0
Do
Call Dopn64_r(N, T, Y(), Yp(), Tout, Tend, RTol(), ATol(), Mode, Info, TT, YY(), YYpp(), IRev, Neval)
If IRev = 1 Then Call F2(N, TT, YY(), YYpp())
Loop While IRev <> 0
Debug.Print T, Y(0), Y(1)
Loop While Info >= 1 And Info <= 3
Debug.Print Neval, Info
End Sub
Sub Dopn64_r(N As Long, T As Double, Y() As Double, Yp() As Double, Tout As Double, Tend As Double, RTol() As Double, ATol() As Double, Mode As Long, Info As Long, TT As Double, YY() As Double, YYpp() As Double, IRev As Long, Optional Neval As Long, Optional Nstep As Long, Optional Naccept As Long, Optional Nreject As Long, Optional MaxIter As Long=0, Optional ErrCntl As Long=0, Optional Cnt As Long=0, Optional Hinit As Double=0, Optional Hmax As Double=0, Optional Fac1 As Double=0, Optional Fac2 As Double=0, Optional Safe As Double=0)
Initial value problem of ordinary differential equations (6(4)-th order Runge-Kutta-Nystrom method) (...
Note - If Mode is chenged to 3 instead of 2 in the same program, the dense outout (interpolation) is used.
Example Results
1 0.294417537532138 0.812178519518601
2 -0.490299794708535 0.939874996143069
3 -1.05403151990242 0.575706077688165
4 -1.25000000646059 -7.04494723513782E-11
5 -1.0540315281981 -0.575706078121179
6 -0.490299814715182 -0.939875001277057
7 0.294417509428625 -0.812178544883837
8 0.749999999192525 -4.83130191495817E-08
9 0.294417562346843 0.812178494364129
10 -0.490299778552138 0.939874988865652
11 -1.05403151394831 0.575706073120601
12 -1.25000000644411 -4.91406552066039E-09
1101 0